设为首页 - 加入收藏
广告 1000x90
您的当前位置:主页 > 自媒体运营 > 正文

wordpress分类目录添加自定义head内容

来源:网络分享 编辑:引流技巧 时间:2025-05-14

head头部有很多代码都和seo有关,比如可以添加规范标签canonical、robots.txt标签等等。那么如何自定义在分类中添加head代码呢

wordpress

代码

  • //自定义添加head代码
  • global $texonomy_slug_definedhead;
  • $texonomy_slug_definedhead='category';
  • add_action($texonomy_slug_definedhead.'_add_form_fields','categorydefinedhead');
  • function categorydefinedhead($taxonomy){ ?>
  • <div>
  • <label for="tag-definedhead">自定义head</label>
  • <input type="text" name="tag-definedhead" id="tag-definedhead" value="" /><br /><span>输入head代码</span>
  • </div>
  • <?php }
  • add_action($texonomy_slug_definedhead.'_edit_form_fields','categorydefinedheadedit');
  • function categorydefinedheadedit($taxonomy){ ?>
  • <tr class="form-field">
  • <th scope="row" valign="top"><label for="tag-definedhead">自定义head</label></th>
  • <td><input type="text" name="tag-definedhead" id="tag-definedhead" value="<?php echo get_option('_category_definedhead'.$taxonomy->term_id); ?>" /><br /><span class="description">输入head代码</span></td>
  • </tr>
  • <?php }
  • add_action('edit_term','categorydefinedheadsave');
  • add_action('create_term','categorydefinedheadsave');
  • function categorydefinedheadsave($term_id){
  • if(isset($_POST['tag-definedhead'])){
  • if(isset($_POST['tag-definedhead']))
  • update_option('_category_definedhead'.$term_id,$_POST['tag-definedhead'] );
  • }
  • }
  • 在函数模板上面的代码,添加一个字段

    调用

  • //
  • 分类添加自定义head
  • <?php
  • if(is_category()){
  • $title = the_zm_title();
  • $category_info = get_the_category();
  • $category_id = $category_info[0]->cat_ID;
  • $cat_definedhead = get_option('_category_definedhead'.$category_id);
  • ?>
  • <?php echo $cat_definedhead;?>
  • <?php } ?>
  • 将代码放到header中使用即可

    相关推荐:

    栏目分类

    微商引流技巧网 www.yinliujiqiao.com 联系QQ:1716014443 邮箱:1716014443@qq.com

    Copyright © 2019-2024 强大传媒 网站地图 rss地图

    Top