功能介绍
当写完文章之后,标签不知道设置什么好点或者说是不想设置的时候,就可以说使用该功能,启用该功能之后可自动为文章添加已使用过标签
配置教程
首先利用宝塔或则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'); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容