wordpress分类自定义添加关键词

wordpress分类自定义添加关键词

wordpress分类自定义添加关键词

在当前主题的functions.php文件中添加以下代码:

<?phpglobal $texonomy_slug_keywords;$texonomy_slug_keywords='category';add_action($texonomy_slug_keywords.'_add_form_fields','categorykeywords');function categorykeywords($taxonomy){ ?> <div> <label for="tag-keywords">分类关键词</label> <input type="text" name="tag-keywords" id="tag-keywords" value="" /><br /><span>请在此输入分类关键词。</span> </div><?php }add_action($texonomy_slug_keywords.'_edit_form_fields','categorykeywordsedit');function categorykeywordsedit($taxonomy){ ?><tr class="form-field"> <th scope="row" valign="top"><label for="tag-keywords">关键词</label></th> <td><input type="text" name="tag-keywords" id="tag-keywords" value="<?php echo get_option('_category_keywords'.$taxonomy->term_id); ?>" /><br /><span class="description">请在此输入分类关键词。</span></td></tr> <?php }add_action('edit_term','categorykeywordssave');add_action('create_term','categorykeywordssave');function categorykeywordssave($term_id){ if(isset($_POST['tag-keywords'])){ if(isset($_POST['tag-keywords'])) update_option('_category_keywords'.$term_id,$_POST['tag-keywords'] ); }}?>

 

在header.php文件中添加该字段内容作为分类keywords:

 

<?php if(is_category()){ $category_info = get_the_category(); $category_id = $category_info[0]->cat_ID; $cat_keywords = get_option('_category_keywords'.$category_id);?><meta name="keywords" content="<?php echo $cat_keywords;?>"/><?php } ?>

转载请注明出处::【风酷SEO】 » wordpress分类自定义添加关键词

评论 0


Fatal error: Call to undefined function hui_user_avatar() in D:\wwwroot\fengkunet\wwwroot\wp-content\themes\xiu\functions.xiu.php on line 788