将下方的代码复制粘贴到你所使用的主题函数function.php文件中
function zm_auto_add_tags() {
$post_id = get_the_ID();
if ( $post_id ) : $post_content = get_post( $post_id )->post_content;
if ( !empty( $post_content ) ) {
$tags = get_tags( array( 'hide_empty' => false ) );
if ( $tags ) {
$i = 0;
foreach ( $tags as $tag ) {
if ( strpos( $post_content, $tag->name ) !== false ) {
if ( $i == 6 ) break; // 添加数量
wp_set_post_tags( $post_id, $tag->name, true );
$i++;
}
}
}
}
endif;
}
add_action( 'save_post', 'zm_auto_add_tags' );
注意,此功能如果你的标签数量极多,大于几千个标签数量的时候,发布更新文章时可能会卡死状态文章源自小虫博客-https://www.xczi.cn/wordpress/632.html 文章源自小虫博客-https://www.xczi.cn/wordpress/632.html
评论