I’d like to run some code only if a gallery (inserted with the shortcode) has been inserted into a post/page. I did the following:

gallery_shortcode($post->ID) ?
$gallery = 1 : $gallery = 0;

However, this always sets $gallery = 0 whether there’s a gallery or not. Am I using this incorrectly?

3 s
3

try :

if (strpos($post->post_content,'[gallery') === false){
  $gallery = 0;
}else{
  $gallery = 1;
}

Leave a Reply

Your email address will not be published. Required fields are marked *