Skip to content

Instantly share code, notes, and snippets.

Created January 25, 2016 15:56
Show Gist options
  • Save anonymous/b9f70ad35a9051980eaf to your computer and use it in GitHub Desktop.
Save anonymous/b9f70ad35a9051980eaf to your computer and use it in GitHub Desktop.
WordPress shortcode to display a category description?
Try this. Add the code below to your functions.php file -
add_shortcode('cat_description', 'my_cat_description_shortcode');
function my_cat_description_shortcode($atts){
$a = shortcode_atts( array(
'id' => 0,
), $atts );
return category_description($a['id']);
}
Should you wish to call the shortcode from a template (unnecessary really unless you add more to the shortcode) you can use this code -
<?php echo do_shortcode('[cat_description id="' . $category_id . '"]'); ?>
Here is some recommended reading for you -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment