共计 415 个字符,预计需要花费 2 分钟才能阅读完成。
如果不想手动添加标签,可以纯代码实现自动添加标签,不过只能添加已存在的标签。
在 function.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 the tag is already used in the post content, add it to the post tags | |
if (strpos($post_content, $tag->name) !== false) { | |
wp_set_post_tags($post_id, $tag->name, true); | |
} | |
} | |
} | |
} |
提醒:本文发布于784天前,文中所关联的信息可能已发生改变,请知悉!
AD:【腾讯云服务器大降价】2核4G 222元/3年 1核2G 38元/年
正文完