• Resolved RE20

    (@re20)


    Hi,
    Trying to write an IF statement based on the value of a shortcode. Any ideas?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    are you putting the “if” inside the code or what? Please explain your use case.

    Thread Starter RE20

    (@re20)

    sorry, that would have been a smart idea from the beginning. I’m using custompress from wpmu dev, and one of the custom fields I setup is a radio button. and here is the PHP shortcode they provide <?php echo do_shortcode('[ct id="_ct_checkbox_578e5d6304573" property="title | description | value"]'); ?>

    The value it will spit out will either be YouTube or Vimeo and I’m trying make the shortcode an IF state so IF value is youtube show this and IF value is vimeo show this.

    Hope this helps. Thanks

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    A shortcode returns a string, so you can look at that string in your code and modify it via str_replace() or a more fancy regex based replace. If that’s what you want to do, I’d use

    $field = do_shortcode( '[whatever]' );

    then do what needs to be done with $field and echo that result.

    Thread Starter RE20

    (@re20)

    Ok great thanks. now i need to figure out how to get if $field equals A show this else show b. Thoughts

    Thread Starter RE20

    (@re20)

    NEVER MIND I GOT IT

    <?php
    $field = do_shortcode('[yadayda]');
    
    if($field !== 'A') {
    
        echo $field;
    
    } else {
    
        echo 'B';
    
    }
     ?>
    </div>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘if Shortcode is???’ is closed to new replies.