Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #293107

    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?

    #293172

    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

    #293196

    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

    #293197

    Ah, I wasn’t quite sure but glad you found a good working fix.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.