Article directory
How to create a shortcode to display category description?
For example, you could want to display the WordPress category description shown in the image below on a specific post page:

How to create a WordPress shortcode to get the specified category image description display?
Say you want to be able to display certain posts and product (WooCommerce) category descriptions on pages or posts via shortcodes, but don't know how to create a simple WordPress shortcode using code.
Please add the following code to the functions.php file:
//WordPress简码获取指定分类目录图像描述显示
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']); }
If you want to call a WordPress shortcode from a template (unnecessary unless you add more content to the shortcode) you can use this code:
<?php echo do_shortcode(''); ?>- among them
category_idis the ID of the category.
How to get the current category description display of WordPress on the specified article page through WP shortcode?
To display the category description on the specified article page, add the following WordPress shortcode:
- If the quotation marks in the category description shortcode id are left blank, you can directly call the current WordPress category description image.
Hopefully, the article "How to Create a WordPress Shortcode to Get Image Descriptions for a Specific Category?" shared on Chen Weiliang's blog ( https://www.chenweiliang.com/ ) will be helpful to you.
Feel free to share this article's link: https://www.chenweiliang.com/cwl-20133.html
