声明:本站源码仅做学习研究,严禁用于任何商业用途以及任何变现!
功能介绍
当写完文章之后,标签不知道设置什么好点或者说是不想设置的时候,就可以说使用该功能,启用该功能之后可自动为文章添加已使用过标签
配置教程
首先利用宝塔或则FTP打开/inc/options下的admin-options.php文件把下面代码放在20行左右
array(
'id' => 'is_automatically_add_labels',
'type' => 'switcher',
'title' => '自动添加标签',
'label' => '启用后可自动为文章添加已使用过标签',
'default' => false,
),
最后在主题根目录下打开functions.php将以下代码放在最后即可
//+----------------------------------------------------------------------
//| 自动为文章添加标签
//+----------------------------------------------------------------------
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 );
}
}
}
if(_cao('is_automatically_add_labels')){
add_action('save_post', 'auto_add_tags');
}
声明:本站所有文章,来源于互联网收集至此,所有资源仅供学习研究,商业运营请支持正版。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理 !