Check if post has a gallery

A simple check if the current postpage has a gallery shortcode within the post_content. Show different output for each case in your template with this snippet.

/**
 * Snippet Name: Check if post has a gallery
 * Snippet URL: https://www.wpcustoms.net/snippets/check-post-gallery/
 */
  if (strpos($post->post_content,'[gallery') === false){
  $gallery = 0; 
// false - no gallery found
} else {
  $gallery = 1; 
// true - this postpage has a gallery
} 

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x