欢迎光临
我们一直在努力

wordpress如何将文章tag标签链接改成数字id.html链接,纯代码无插件

wordpress文章tag标签默认链接是用中文字显示的,中文状态下是不利于seo优化的,不过有的是我们自定义设置英文拼音的。今天WordPress建站的小编着重介绍一下怎么把链接改成数字id.html(无需插件)。

打开主题functions.php,在最下面插入以下代码:

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;
}

 

现在相关链接已经修改好了,但是页面是会出现404,所以这时需要重新打开后台工具中“固定链接”页面重新保存即可!

赞(2) 打赏
未经允许不得转载:新起点博客 » wordpress如何将文章tag标签链接改成数字id.html链接,纯代码无插件


关注公众号『新起点软件管家』

获取最新网络资源及破解软件!
带你玩转各样软件...

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏