Check If a WordPress Post or Page Has a Gallery Inserted In It

Place this in a WordPress template file (like single.php) to check if a post has a gallery inserted into it.

if (strpos($post->post_content,'[gallery') === false){
  $gallery = 0;
  // no gallery, so do what you want here

}else{
  $gallery = 1;
  // yes sir, there's a gallery on this post, so do something
}

See more:

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]