繁体   English   中英

如何在WordPress中更改标签URL

[英]How to change the tags url in wordpress

我从这样的wordpress标签获取网址

www.xxxxxx.com/?tag=chromatography

但我想要这样

www.xxxxxx.com/?s=chromatography

谁能告诉我如何更改从标记生成的网址设置?

任何帮助都是可观的

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

这应该可以解决问题:

RewriteEngine On
RewriteCond %{QUERY_STRING} s=(.+)
RewriteRule ^/?(index.php)?$ /?tag=%1 [R,L]

上面的意思是,访问http://yoursite.com/index.php?s=chromatographyhttp://yoursite.com/?s=chromatography任何人都将在其地址栏中看到该URL,但是Wordpress会将其理解为含义http://yoursite.com/?tag=chromatography

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

要更改wordpress本身为标签提供的URL,可以应用过滤器 ,如get_tag_link文档中get_tag_link

为此,将以下内容添加到主题的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);

注意:该PHP代码未经测试,但据我所知应该可以解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM