今天博主给大家分享一篇自动给文章添加TAG标签的WordPress教程,其实也非常的简单只需要把下面的代码添加到主题的functions.php里即可。
//自动为文章添加标签
add_action('save_post', 'auto_add_tags');
function auto_add_tags(){
$tags = get_tags( array('hide_empty' => false) );
$post_id = get_the_ID();
$post_content = get_post($post_id)->post_content;
if ($tags) {
foreach ( $tags as $tag ) {
// 如果文章内容出现了已使用过的标签,自动添加这些标签
if ( strpos($post_content, $tag->name) !== false)
wp_set_post_tags( $post_id, $tag->name, true );
}
}
}
上文分享了给文章自动添加TAG标签方法,那么如果我们希望TAG标签能够自动链接到对应的文章该怎么实现呢?
可以看看这篇文章,有详细的讲解:

© 版权声明
THE END
喜欢就支持一下吧
请登录后发表评论
注册
社交帐号登录