0

first of all im new to Wordpress and PHP and i apologize if this is a basic question. I have a Wordpress installation and every post is marked with Tags and these Tags contain a link with:

href=domain.com/index.php/tag/TAGNAME

but i want the Link to be:

href=domain.com/index.php/search/TAGNAME

As far as i understand it i need to change the get_tag_link() but all is does is use the get_term_link() and then im totaly lost. Is there somewere a function which says If(tag){ return "/tag/"} which i can modify? The Theme i use uses this function for "breadcrumbs" http://dimox.net/wordpress-breadcrumbs-without-a-plugin/ but i dont know if this i relevant in any form.

Thank you very much.

1

I used a workaround for now. I eddited the category_template.php with the str_replace function. The problem turned out to be that the Tag Cloud used diffenten functions than the regular Tags. I just added this:

foreach ( $tags_data as $key => $tag_data ) {

$class = $tag_data['class'] . ' tag-link-position-' . ( $key + 1 );
 $a[] = "<a href='" . str_replace("/index.php/tag/","/index.php/search/",esc_url( $tag_data['url'] )) .(...)
}

to wp_generate_tag_cloud() and this:

$the_tags = str_replace("/index.php/tag/","/index.php/search/",$the_tags);

to the_tags(). As stated bevor I'm new to this and I dont think thats the way it should be but it works for now. I used it with the BeTube Theme if anyone wants to use this as well.

Thanks for your answers.

1

You just need to change your Tag base in permalinks setting on your website.

enter image description here

PS : By default /search/ is a slug for a search result page. To avoid conflict with search result page you may also need to rewrite search url. check this page to rewrite search url

https://bavotasan.com/2011/rewrite-search-result-url-for-wordpress/

  • Thanks, but i actually wanted to provoke this conflict since i didn't know how to start a search for post based on Tags. I tried it and it automatically changes my search url. – Jan Lenzen May 18 '17 at 22:54
  • I tried this on my localsite and its worked. I change my search url with /browse/ and didnt find any conflict – rheeantz May 18 '17 at 22:59
0

You can rewrite the URLs in .htaccess:

RewriteEngine On
RewriteRule ^tag/(.*)$ http://example.com/search/$1 [R=301,L]

Put this above the default WP .htaccess contents and replace example.com with your actual domain.

  • Thanks, but I think i dont have a .htaccess, i run this Wordpress on an nginx Server – Jan Lenzen May 18 '17 at 22:58
  • Depends on the host, some enable .htaccess even on Nginx, but it will be faster if you use Nginx's own redirect methods: nginx.com/blog/creating-nginx-rewrite-rules – WebElaine May 19 '17 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.