I was trying to use
<?php
if (strpos($post->post_content,'[gallery') !== false){
echo do_something;
} else {
do_somethingelse;
}
?>
and I am not getting any results.
I could create a new custom field called Gallery and check for that but it adds another step.
Is there a better way to check if a post has a gallery?
Hi Monsoon!
Are you purposely putting the gallery shortcode with only the starting [ or is that a potential error in the code? Just a cursory glance and it stood out.
Cheers!
Devin
Nope it works with just the starting one but I think the theme is not using the default [gallery] shortcode…correct?
Anyway I needed a quick fix so instead of checking if the post has a gallery I created a category called Photos and simply do a check to see if that category is selected with the post that way I can have more control and have a gallery but not act on it depending on he post…much better than adding a custom field on each post
Ah, I wasn’t quite sure but glad you found a good working fix.