Support » Plugins » Hacks » How to write and Echo Shortcode Content

  • does anyone know how to write a shortcode to display a users content between tags, then echo that content later in a conditional?

    say someone enters this in the editor
    [sc1]this is shortcode 1 content[/sc1]
    [sc2]this is shortcode 2 content[/sc2]

    i then would need to write a conditional into my loop

    if ($function) {
    echo sc1;
    }else{
    echo sc2;
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • Anjara

    (@hiteshanjara)

    Hello,

    This link will help you – http://codex.wordpress.org/Shortcode_API

    @hiteshanjara thanks..

    thanks @hiteshanjara… i think the shortcode is the easy part, unless id have to write a conditional shortcode to make this work. then im lost.

    Right now i have this.

    function sc1( $atts, $content=null) {
    return do_shortcode($content); }
    add_shortcode( 'sc1', 'sc1' );
    
    function sc2( $atts, $content=null) {
    return do_shortcode($content); }
    add_shortcode( 'sc2', 'sc2' );

    im now looking for how to echo the content into a conditional
    i tried the following in various ways, it didnt work.

    if ($function) {
    echo do_shortcode('[sc1]' . $content . '[/sc1]');
    }else{
    echo do_shortcode('[sc2]' . $content . '[/sc2]');
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to write and Echo Shortcode Content’ is closed to new replies.