wordpress tag标签改造id显示加后缀html显示

wordpress tag标签改造id显示加后缀html显示,对seo来说是特别友好的。使用文本编辑器打开当前主题目录下的 functions.php,添加以下 php 代码:

/* 标签以id+html方式展示*/
 
add_action('generate_rewrite_rules','tag_rewrite_rules');
 
add_filter('term_link','tag_term_link',10,3);
 
add_action('query_vars', 'tag_query_vars');
 
function tag_rewrite_rules($wp_rewrite){
 
    $new_rules = array(
 
        'tag/(\d+)/feed/(feed|rdf|rss|rss2|atom).html' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
 
        'tag/(\d+)/(feed|rdf|rss|rss2|atom).html' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
 
        'tag/(\d+)/embed.html' => 'index.php?tag_id=$matches[1]&embed=true',
 
        'tag/(\d+)/page/(\d+).html' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',
 
        'tag/(\d+).html' => 'index.php?tag_id=$matches[1]',
 
    );
 
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
 
}
 
function tag_term_link($link,$term,$taxonomy){
 
    if($taxonomy=='post_tag'){
 
        return home_url('/tag/'.$term->term_id.'.html');
 
    }
 
    return $link;
 
}
 
function tag_query_vars($public_query_vars){
 
    $public_query_vars[] = 'tag_id';
 
    return $public_query_vars;
 
}
声明

⚠️免责声明:本站的资源均来自于用户投稿,仅为资源共享、作个人学习使用,其版权均归原作者所有。

⚠️侵权声明:如有侵权请发送邮件至:xjbqb@foxmail.com 或 点击右侧 私信:“管理员”反馈,我们将尽快处理。

⚠️转载声明:若需转载,请保留原文链接并附出处,谢谢合作。

给TA打赏
共{{data.count}}人
人已打赏
技术教程

wordpress建站必做的基础优化

2023-11-30 17:38:34

技术教程

WordPress:解决xmlrpc.php被扫描爆破的风险

2023-12-1 22:07:51

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
我是底线可爱胖!冲鸭~