Article directory
How to create a shortcode to display category description?
For example, think in the picture belowWordPressCategory description, which is displayed on the specified article 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_id
is 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.
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How to create a WordPress shortcode to get the image description display of a specified category?", which is helpful to you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-20133.html
Unlock AI assistance and say goodbye to inefficient work! 🔓💼
🔔 Get the "DeepSeek Prompt Word Tool" immediately in the channel pinned directory! 🎯
📚 Miss out = Fall behind forever! Act now! ⏳💨
If you like it, please share and like it! Your sharing and likes are our continuous motivation!