wordpress tags标签改id和后缀html显示

赵斌博客
2022-08-12 / 0 评论 / 331 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年08月12日,已超过621天没有更新,若内容或图片失效,请留言反馈。
广告

​​wordpress tags标签改造id显示加后缀html显示,对seo来说是特别友好的。

wordpress tags标签改id和后缀html显示

使用文本编辑器打开当前主题目录下的 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;
}
本文共 58 个字数,平均阅读时长 ≈ 1分钟
广告
0

打赏

海报

正在生成.....

评论 (0)

取消