Can't put code to shortcode
-
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.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Can't put code to shortcode’ is closed to new replies.