用户
ID: 剩余积分:
积分仅限于AI文章写作也可以用于Wordpress下的SEO合集插件“智能改写”“词库挖掘”“关键词排名监控”“AI智能DK”功能使用;
充值仅用于消费,不可变更,退款,提现,请慎重选择!
用户邮箱
验证码
暂无数据
网站运行SEO是必不可少的一项功能,增加自然排名,增加人气,一个网站才能正式的获取到用户和粉丝。
对于wordpress来说,分类页占有很大的比重,所以分类页的SEO才显得尤为重要。
那么怎么给分类页添加 seo关键词和描述呢?有人会说,怎么没有提title的事,对于分类页来说,最好的标题当然是分类名称了,再设置其它的,不但多此一举还会让搜索引擎蜘蛛抓取出现混乱。
一、主题自带功能
如下:在分类设置中可以看到seo关键词的设置,但是没有描述,有标题(不推荐使用)。这种就是主题自带的,但是这个主题带的不是那么实用。
缺点:您喜欢的主题不一定有完全的功能。
二、插件含有的功能
例如:seo合集插件的就包含分类的seo关键词和描述。需要注意的是主题包含的可能会替换插件的功能,所以使用的时候可以联合使用。主题包含关键词,那么使用主题的关键词,插件包含描述,使用插件的描述。如果主题包含的完全了就不要使用插件的功能了。如果主题不包含,直接用插件的会更好用。
缺点:功能可能会被主题给替换掉,如果主题包含部分功能,与插件联合使用不太好设置。
一、代码实现
1)、分类页添加设置,主题function.php下设置如下代码
<xmp>
add_action( 'category_add_form_fields', 'category_term_field' );//分类
function category_term_field() {
echo '<div class="form-field category-term-field">
<div class="form-field category-term-field">
<label for="category-term-seo_keywords">SEO关键词</label>
<textarea name="category_term_seo_keywords" id="category-term-seo_keywords"></textarea>
</div>
<div class="form-field category-term-field">
<label for="category-term-seo_description">SEO描述</label>
<textarea name="category_term_seo_description" id="category-term-seo_description"></textarea>
</div>';
}
</xmp>
2)、
编辑页面设置,添加页面和编辑页面的方法可以合并为一个方法,根据页面判断进行css样式加载,这里不做演示
<xmp>
Add_action( 'category_edit_form_fields', 'edit_category_term_field' );
function edit_category_term_field( $term ) {
$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">
<th scope="row">
<label for="category-term-keywords">SEO关键词
</label></th>
<td>
<textarea name="category_term_keywords" id="category-term-keywords">'.$category_keywords.'</textarea>
</td>
</tr>
<tr class="form-field category-term-field-wrap">
<th scope="row"><label for="category-term-des">SEO描述</label></th>
<td>
<textarea name="category_term_des" id="category-term-des">'.$category_des.'</textarea>
</td>
</tr>';
}
</xmp>
3)、保存数据到数据库
<xmp>
add_action( 'create_category', 'save_category_term_field' );
add_action( 'edit_category', 'save_category_term_field' );
function save_category_term_field( $term_id ) {
$category_keywords = isset( $_POST['category_term_keywords'] )?$_POST['category_term_keywords'] : '';
$category_des = isset( $_POST['category_term_des'] ) ? $_POST['category_term_des'] : '';
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 );
}
</xmp>
4)、前端调用
<xmp>
add_action('wp_head','wztkj_mainpage',1);
Function wztkj_mainpage(){
if( ( is_category() ) ){
$category_k=get_term_meta($term->term_id,'category_seo_keywords', true );
$category_des = get_term_meta( $term->term_id, 'category_seo_des', true );
echo'<meta name="keywords"content="'.$category_k.'">'."\n\r";
echo '<meta name="description" content="'.$category_des.'">'."\n\r";
}
}
</xmp>
优点:可以找出主题自带的该功能,在其基础上修改兼容性好
缺点:需要有一定的代码编辑能力。