[[SEO技术]] 怎样给分类目录添加SEO标题和关键词?

[复制链接]
查看: 80|回复: 0
发表于 2023-6-24 16:03:42 | 显示全部楼层 | 阅读模式
易博V9下载

作为一个wordpress网站的站长,都希望自己的网站在百度或谷歌搜索引擎上的排名好。这时,我们除了要做好wordpress网站的内容之外,还要对wordpress网站做好相关的SEO优化。在前面的章节中,我们介绍了wordpress网站首页的SEO优化,今天,我们再来介绍一下wordpress网站的分类目录页面的SEO优化。

怎样给分类目录添加SEO标题和关键词?

wordpress网站

我们都知道,分类目录的标题一般都比较短,有的只有2个字,这很利于SEO优化,所以,我们将为wordpress网站的分类目录后台界面添加SEO标题、关键词、描述功能,这样,我们在添加或修改分类目录时,就可以为每一个分类目录创建SEO标题、关键词和描述了。下面,就随我一起来看看吧。具体可以观看我在本站发表的《怎样给wordpress网站的分类目录,添加SEO标题和关键词?》视频。

第一步:添加后台“添加界面”。

给wordpress网站的后台的“添加新分类目录”界面,增加几个SEO表单。“添加新分类目录”界面默认情况下如下图。

怎样给分类目录添加SEO标题和关键词?

添加新分类目录

把下面的代码,放到wordpress主题的functions.php文件中。

//给分类目录添加 SEO标题、关键词、描述//添加页面 挂载字段add_action( ‘category_add_form_fields’, ‘category_term_field’ );//分类add_action( ‘post_tag_add_form_fields’, ‘category_term_field’ );//标签function category_term_field() {wp_nonce_field( basename( __FILE__ ), ‘category_term_field_nonce’ );//wp_enqueue_script(‘dreamc_term_fields’, get_template_directory_uri(). ‘/js/termmeta-upload.js’);echo ‘<div class=”form-field category-term-field”>’;echo ‘<label for=”category-term-seo_title”>SEO标题</label>’;echo ‘<input type=”text” name=”category_term_seo_title” id=”category-term-seo_title” value=”” />’;echo ‘</div>’;echo ‘<div class=”form-field category-term-field”>’;echo ‘<label for=”category-term-seo_keywords”>SEO关键词</label>’;echo ‘<textarea name=”category_term_seo_keywords” id=”category-term-seo_keywords”></textarea>’;echo ‘</div>’;echo ‘<div class=”form-field category-term-field”>’;echo ‘<label for=”category-term-seo_description”>SEO描述</label>’;echo ‘<textarea name=”category_term_seo_description” id=”category-term-seo_description”></textarea>’;echo ‘</div>’;}

这时,我们再到后台去看一下“添加新分类目录”界面,效果如下图:

怎样给分类目录添加SEO标题和关键词?

SEO表单

第二步:后台分类“编辑界面”添加SEO表单。

默认情况下,wordpress后台的分类编辑界面如下图这样。

我们要给这个分类编辑界面添加SEO标题、关键词、描述的表单。在wordpress主题的functions.php文件中,放入如下代码:

//分类扩展信息 编辑界面add_action( ‘category_edit_form_fields’, ‘edit_category_term_field’ );//分类add_action( ‘post_tag_edit_form_fields’, ‘edit_category_term_field’ );//标签function edit_category_term_field( $term ) {//获取数据$category_title = get_term_meta( $term->term_id, ‘category_seo_title’, true );$category_keywords = get_term_meta( $term->term_id, ‘category_seo_keywords’, true );$category_des = get_term_meta( $term->term_id, ‘category_seo_des’, true );echo ‘<tr class=”form-field category-term-field-wrap”>’;echo ‘<th scope=”row”><label for=”category-term-title”>SEO标题</label></th>’;echo ‘<td>’;echo wp_nonce_field( basename( __FILE__ ), ‘category_term_field_nonce’ );echo ‘<input type=”text” name=”category_term_title” id=”category-term-title” value=”‘.$category_title.'”/>’;echo ‘</td>’;echo ‘</tr>’;echo ‘<tr class=”form-field category-term-field-wrap”>’;echo ‘<th scope=”row”><label for=”category-term-keywords”>SEO关键词</label></th>’;echo ‘<td>’;echo ‘<textarea name=”category_term_keywords” id=”category-term-keywords”>’.$category_keywords.'</textarea>’;echo ‘</td>’;echo ‘</tr>’;echo ‘<tr class=”form-field category-term-field-wrap”>’;echo ‘<th scope=”row”><label for=”category-term-des”>SEO描述</label></th>’;echo ‘<td>’;echo ‘<textarea name=”category_term_des” id=”category-term-des”>’.$category_des.'</textarea>’;echo ‘</td>’;echo ‘</tr>’;}

我们再到后台的分类目录编辑界面看一下,效果如下图:

怎样给分类目录添加SEO标题和关键词?

分类目录编辑界面看一下

第三步:添加“保存数据”的代码。

我们在wordpress网站后台的分类目录界面添加或修改数据后,我们还需要对它们进行保存,所以,我们需要functions.php文件添加如下这段保存数据的代码:

//保存数据add_action( ‘create_category’, ‘save_category_term_field’ );add_action( ‘edit_category’, ‘save_category_term_field’ );//分类add_action( ‘create_post_tag’, ‘save_category_term_field’ );add_action( ‘edit_post_tag’, ‘save_category_term_field’ );//标签function save_category_term_field( $term_id ) {if ( ! isset( $_POST[‘category_term_field_nonce’] ) || ! wp_verify_nonce( $_POST[‘category_term_field_nonce’], basename( __FILE__ ) ) )return;//获取$category_title = isset( $_POST[‘category_term_title’] ) ? $_POST[‘category_term_title’] : ”;$category_keywords = isset( $_POST[‘category_term_keywords’] ) ? $_POST[‘category_term_keywords’] : ”;$category_des = isset( $_POST[‘category_term_des’] ) ? $_POST[‘category_term_des’] : ”;//更新if( ” === $category_title){delete_term_meta( $term_id, ‘category_seo_title’ );}else{update_term_meta( $term_id, ‘category_seo_title’, $category_title );}if( ” === $category_keywords){delete_term_meta( $term_id, ‘category_seo_keywords’ );}else{update_term_meta( $term_id, ‘category_seo_keywords’, $category_keywords );}if( ” === $category_des){delete_term_meta( $term_id, ‘category_seo_des’ );}else{update_term_meta( $term_id, ‘category_seo_des’, $category_des );}}

通过上面几步,我们就为我们的wordpress网站的分类目录添加了SEO标题、关键词、描述的功能,以后,我们在添加分类目录时,填写这些信息,然后,再在前台模板的头部调用,就可以实现wordpress网站分类目录页面的SEO优化了。

易博软件介绍
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1、请认真发帖,禁止回复纯表情,纯数字等无意义的内容!帖子内容不要太简单!
2、提倡文明上网,净化网络环境!抵制低俗不良违法有害信息。
3、如果你对主帖作者的帖子不屑一顾的话,请勿回帖。谢谢合作!
3、问答求助区发帖求助后,如有其他用户热心帮您解决问题后,请自觉点击设为最佳答案按钮。

 
 
QQ在线客服
QQ技术支持
工作时间:
8:00-18:00
软著登字:
1361266号
官方微信扫一扫
weixin

QQ|小黑屋|慈众营销 ( 粤ICP备15049986号 )|网站地图

自动发帖软件 | 自动发帖器 | 营销推广软件 | 网络营销工具 | 网络营销软件 | 网站推广工具 | 网络推广软件 | 网络推广工具 | 网页推广软件 | 信息发布软件 | 网站推广工具 | 网页推广软件

Powered by Discuz! X3.4   © 2012-2020 Comsenz Inc.  慈众科技 - Collect from 深圳吉宝泰佛文化有限公司 公司地址:罗湖区黄贝街道深南东路集浩大厦A1403

返回顶部 返回列表