如果不想手动添加标签,可以纯代码实现自动添加标签,不过只能添加已存在的标签。
在 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);
}
}
}
}