在WordPress 指定某个分类的文章结尾插入简码
用户需求
用户要在wordpress网站文章结尾插入一个自定义表单,而且要指定某个分类下的文章,不是全部文章。
本案例总共有2个自定义表单,插入在不同的分类下面。
添加步骤
1、利用主题的Html Block 创建好表单内容,这里就是我们要插入的自定义内容块,这样我们就得到2个简码。

2、通过文章分类的别名判断是哪个分类,我们只要需要插入对应的分类别名。
插入代码
在子主题的functions.php 下面添加代码,简码和内容,自行修改。
function auto_insert_after_post($content){
$your_custom_text = do_shortcode(''); //自定义内容1
$your_custom_text2 = do_shortcode(''); //自定义内容2
global $post;
if ( in_category(array( 'luyan') ) //自定义内容1,插入到1个指定分类 )
{
$content = $content.$your_custom_text;
}
if ( in_category( array( 'yuyue', 'luyan2') ) //自定义内容2,插入到2个分类 )
{ $content = $content.$your_custom_text2;
} return $content;
}
add_filter( 'the_content', 'auto_insert_after_post' );
效果预览

其它
如果判断不同的文章类型type插入内容?请看
