3

I have two Wordpress sites that share the same template files for two languages. I want to change the search base word for the non-english website. However, when I change the

var $search_base = 'search';

from the rewrite.php file, it does it for both languages. Is there any way to do it only for the non-english?

Edit: Cannot see why my question has been marked as duplicate and especially with that question which has nothing to do with mine. I can change the search base, but I want to do it only for one language and not all of them. The duplicate question has the same result as mine.

I tried something like this in the function.php file, but still it doesn't work:

$lang = get_bloginfo("language");
if ( $lang == 'de-DE' ) {
    add_action('init', 'search_base_german');
    function search_base_german() {
        $search_slug = 'suche'; // change slug name
        $GLOBALS['wp_rewrite']->search_base = $search_slug;
    }
}
6
  • @toscho..Have you tried to read the question before marked it as duplicated? If I could just follow an answer from another question, I wouldn't ask a new one. My question is different since I have a multilanguage installation and I want to change it only in one language.
    – Tasos
    Sep 2, 2015 at 12:38
  • Please add an explanation about your language setup to the question. In a multisite, you can activate a plugin with the linked just on the site where you need the changes.
    – fuxia
    Sep 2, 2015 at 13:06
  • 1
    @toscho Using multisites. One Wordpress installation with one template folder and many wordpress sites. Each of them a different language.
    – Tasos
    Sep 2, 2015 at 14:23
  • Then why can't you just use that code in a plugin that is active on one site?
    – fuxia
    Sep 2, 2015 at 17:47
  • Both sites have the same plugin. There isn't any way to add a code on a file only for one site. That's why I tried in my edit to use an if statement yo identify the language.
    – Tasos
    Sep 2, 2015 at 18:35

1 Answer 1

2

I found the solution. I had to flush rules after I change the search base with the code on the edited question. Here is the final code:

$lang = get_bloginfo("language");
if ( $lang == 'de-DE' ) {
    add_action('init', 'search_base_german');
    function search_base_german() {
        $search_slug = 'suche'; // change slug name
        $GLOBALS['wp_rewrite']->search_base = $search_slug;
        $GLOBALS['wp_rewrite']->flush_rules();
    }
}
3
  • This it a totally wrong place to flush rules as it will cause a database write every page load. flushing rules should be done manually (saving the permalink page) at admin context, or you can first check that the base was changed before flushing. Sep 3, 2015 at 14:39
  • @Mark any other idea how this could be done?
    – Tasos
    Sep 3, 2015 at 17:54
  • hmmm, all were listed in my comment Sep 3, 2015 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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