Php 如何在wordpress中更改标签url

Php 如何在wordpress中更改标签url,php,wordpress,Php,Wordpress,我从wordpress标签中获取url,如下所示 www.xxxxxx.com/?tag=chromatography www.xxxxxx.com/?s=chromatography 但是我想要这样 www.xxxxxx.com/?tag=chromatography www.xxxxxx.com/?s=chromatography 有人能告诉我如何更改从标记生成的url设置吗 任何帮助都很有用您可以在本地.htaccess文件或主Apache VirtualHost文件(假设您使用的

我从wordpress标签中获取url,如下所示

www.xxxxxx.com/?tag=chromatography
www.xxxxxx.com/?s=chromatography
但是我想要这样

www.xxxxxx.com/?tag=chromatography
www.xxxxxx.com/?s=chromatography
有人能告诉我如何更改从标记生成的url设置吗

任何帮助都很有用

您可以在本地
.htaccess
文件或主Apache VirtualHost文件(假设您使用的是Apache)中使用URL重写()

这应该可以做到:

RewriteEngine On
RewriteCond %{QUERY_STRING} s=(.+)
RewriteRule ^/?(index.php)?$ /?tag=%1 [R,L]
上述情况意味着任何访问
http://yoursite.com/index.php?s=chromatography
http://yoursite.com/?s=chromatography
将在地址栏中看到URL,但Wordpress将理解它的含义
http://yoursite.com/?tag=chromatography

因此,标记行为将按预期运行

要更改wordpress本身为标记显示的URL,可以应用,如的文档中所述

为此,在主题的
functions.php
文件中添加如下内容:

function my_custom_tag_link($taglink, $tag_id) {
  return str_replace($taglink, '?tag=', '?s=');
}
add_filter('tag_link', 'my_custom_tag_link', 10, 2);
N.B.PHP代码没有经过测试,但据我所知,应该可以做到这一点