wordpress tags標(biāo)簽改造id顯示加后綴html顯示

廣告也精彩

wordpress tags標(biāo)簽改造id顯示加后綴html顯示,對(duì)seo來(lái)說(shuō)是特別友好的。

使用文本編輯器打開當(dāng)前主題目錄下的 functions.php,添加以下 php 代碼:

/* 標(biāo)簽以id+html方式展示(molure.cn)*/
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;
}
? 版權(quán)聲明

相關(guān)文章

暫無(wú)評(píng)論

none
暫無(wú)評(píng)論...