WordPress.org

Ready to get started?Download WordPress

Forums

How to write and Echo Shortcode Content (4 posts)

  1. digitalrenewal
    Member
    Posted 2 years ago #

    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;
    }

  2. hiteshanjara
    Member
    Posted 2 years ago #

    Hello,

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

  3. cudjex
    Member
    Posted 2 years ago #

    @hiteshanjara thanks..

  4. digitalrenewal
    Member
    Posted 2 years ago #

    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]');
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags