WordPress.org

Ready to get started?Download WordPress

Forums

Can't put code to shortcode (2 posts)

  1. katalonian
    Member
    Posted 2 years ago #

    Hi all. I want to put this:

    <?php
    $cat = 2;
    $category=get_category($cat);
    // echo "<pre>"; print_r($category); echo "</pre>";
    echo $category->cat_name;
    ?>

    into shortcode.

    For that i doing this:

    function cat_name_shortcode( $atts, $content = null ) {
        extract(shortcode_atts(array(
    		"name" => '3',
    		), $atts));
       return ' <?php
    $cat = ' . $name . ';
    $category=get_category($cat);
    echo $category->cat_name; ?> ' ;
    }
    add_shortcode('cat-name', 'cat_name_shortcode');

    I using this code in template to view shortcode:

    <?php echo do_shortcode('[cat-name name="3"]'); ?>

    But i getting this on front end:

    cat_name; ?>

    What im doing wrong and how i can do that?

    Thanks.

  2. katalonian
    Member
    Posted 2 years ago #

    Hey dudes, can someone help me?

Topic Closed

This topic has been closed to new replies.

About this Topic