Title: has_shortcode cannot catch gallery
Last modified: September 22, 2022

---

# has_shortcode cannot catch gallery

 *  Resolved [ace0930](https://wordpress.org/support/users/ace0930/)
 * (@ace0930)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/has_shortcode-cannot-catch-gallery/)
 * I’m trying to check if the post content has a gallery, and I’m very sure I have
   added a gallery via Gutenberg.
 * But when I use the below code to check, it tells me that there is no gallery 
   in the post content.
 *     ```
       global $post;
   
       if ( ! has_shortcode ( $post -> post_content, 'gallery' ) ) {
         echo 'No gallery';
       }
       ```
   
 * Can you confirm if this is a bug?
 * Or is it possible to check all the shortcodes in the `post_content` and echo 
   them so I can inspect them further?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/has_shortcode-cannot-catch-gallery/#post-16035085)
 * Which gallery did you add? The gallery block within Gutenberg is not the same
   as the [gallery] shortcode. has_shortcode() will find one but not the other. 
   The Gutenberg gallery is not implemented as a shortcode, so extracting any shortcodes
   in content will not yield the results you want.
 * If you want to check for a gallery block in content, you need something like:
   `
   if ( false === strpos( $post->post_content, '<!-- wp:gallery') ) { // etc....`
 *  Thread Starter [ace0930](https://wordpress.org/support/users/ace0930/)
 * (@ace0930)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/has_shortcode-cannot-catch-gallery/#post-16036858)
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/) Thanks, this is working.
   May I know how you find this `<!-- wp:gallery`?
 * Because in the future I might want to check if there is some other Gutenberg 
   block in the content, but I do not know the specific string/keyword to search
   for.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/has_shortcode-cannot-catch-gallery/#post-16037985)
 * Use Gutenberg’s code editor view to see the raw HTML 🙂 (from 3 dot icon’s menu
   at upper right). Every block is demarcated by comments similar to the one for
   galleries. The tag is typically followed by several attributes which keep track
   of the block’s user settings and similar data.
 *  Thread Starter [ace0930](https://wordpress.org/support/users/ace0930/)
 * (@ace0930)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/has_shortcode-cannot-catch-gallery/#post-16038011)
 * [@bcworkz](https://wordpress.org/support/users/bcworkz/) That’s what I’m looking
   for! Thank you so much!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘has_shortcode cannot catch gallery’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [ace0930](https://wordpress.org/support/users/ace0930/)
 * Last activity: [3 years, 8 months ago](https://wordpress.org/support/topic/has_shortcode-cannot-catch-gallery/#post-16038011)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
