Skip to content

Instantly share code, notes, and snippets.

@mrfoxtalbot
Last active January 25, 2016 15:58
Show Gist options
  • Save mrfoxtalbot/5f92ae791dd4c4e26ccd to your computer and use it in GitHub Desktop.
Save mrfoxtalbot/5f92ae791dd4c4e26ccd 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