How to change the tags url in wordpress

I am getting the url from the wordpress tags like this

www.xxxxxx.com/?tag=chromatography

but I want like this

Read More
www.xxxxxx.com/?s=chromatography

Can anybody tell me how can i change the url setting which generate from the tag?

Any help is appreciable

Related posts

1 comment

  1. You can use a URL rewrite (documentation), either in a local .htaccess file or your main Apache VirtualHost file (assuming you are using Apache).

    This should do the trick:

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

    The above means that anyone visiting either http://yoursite.com/index.php?s=chromatography or http://yoursite.com/?s=chromatography will see that URL int he address bar, but WordPress will understand it as meaning
    http://yoursite.com/?tag=chromatography

    So the tag behaviour will function as expected.

    To change the URL which wordpress itself puts out for tags, you can apply a filter, as mentioned in the documentation for get_tag_link.

    For that, add something like the below to your theme’s functions.php file:

    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. That PHP code is not tested, but as far as I can tell should do the trick.

Comments are closed.