Support » Plugin: Multisite Language Switcher » Change the generated URLs

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Dennis Ploetner

    (@realloc)

    You can just add the necessary code to one function.

    Read on here: http://codex.wordpress.org/Conditional_Tags#A_Post_Type

    Cheers,
    Dennis.

    Thanks Dennis,
    This is working very well for my cpt slugs. For my custom tax, it works once in one direction and then stops switching. In other words:

    When I use the switcher like this I have succes:
    eng-custom-tax/eng-post-slug -> fr-custom-tax/fr-post-slug

    But when I use it to go back, this is what I get:
    fr-custom-tax/fr-post-slug -> fr-custom-tax/eng-post-slug

    Any ideas what might be messing up the round trip?

    Just for information: I have my .po and .mo files all good. My custom tax is registered like so:

    'rewrite' => array(
                'slug' => _x('workshop/category', 'URL slug', 'ismh-workshops'),
                'with_front' => true,
                'query_var' => true
            ),

    And in my functions.php I have:

    function my_url_translator( $url, $language ) {
    	if ( 'fr_FR' == $language ) {
    	    $url = str_replace( '/workshop/category/', '/atelier/categorie/', $url );
        }
        return $url;
    }
    add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );

    Thanks

    Plugin Author Dennis Ploetner

    (@realloc)

    It would be interesting to know what’s in $url in the problematic case.

    Plugin Author Dennis Ploetner

    (@realloc)

    Is this problem resolved?

    Hi, thank-you for follow-up; I have been away on holiday and back to this project today.

    No, the issue is not resolved however I am unsure how to answer your question.

    I will try to reiterate the problem here:

    Starting from english:
    domain.dev/workshop/category/youth/
    I click the language switcher which takes me to french:
    fr.domain.dev/atelier/categorie/jeunes/
    Which is the desired outcome.

    From there if I click on the switcher again to go back to english custom category, rather than being take back to the expected domain.dev/workshop/category/youth/, it takes me to domain.dev/atelier/categorie/youth, and obviously a 404 page.

    So while the actual category changes back correctly (“jeunes” goes back to “youth”), the rest of the URL does not goes back from “atelier/category” to “worskhop/category”. From English -> French is no problem, but the other direction does not work.

    For the sake of clarification, this is not specific to only “youth”, but all custom categories.

    Thank-you for any pointers on where I am going wrong.

    I think I may have an idea looking at my code above in my my_url_translator function, which specifies the url replacement from english to french, but perhaps I need also specify from french back to english. I am learning php as I go and I am unsure of this is a case of “multiple if statements” or “else if” but either way I am getting errors. Here is what I am attempting and obviously getting errors:

    function my_url_translator( $url, $language ) {
    	if ( 'fr_FR' == $language ) {
    	    $url = str_replace( '/workshop/category/', '/atelier/categorie/', $url );
        }
        return $url;
    
        }
        if ('fr_FR' !== $language) {
    	    	$url = str_replace( '/atelier/categorie/', '/workshop/category/', $url );
    	    }
    	    return $url;
    }
    add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );

    Thanks

    Plugin Author Dennis Ploetner

    (@realloc)

    Hi,

    the presence of the first return is problematic… Try this:

    function my_url_translator( $url, $language ) {
        if ( 'fr_FR' == $language ) {
            $url = str_replace(
                '/workshop/category/',
                '/atelier/categorie/',
                $url
            );
        }
        else {
            $url = str_replace(
                '/atelier/categorie/',
                '/workshop/category/',
                $url
            );
        }
        return $url;
    }
    add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );

    Yes!! Thank-you so much for all your generous help customizing the functionality of your fantastic plugin Dennis. Is there a way to donate?

    Plugin Author Dennis Ploetner

    (@realloc)

    OK, very good. If you don’t want to donate to Greenpeace – which would be great – consider my Amazon Wishlist. 😉

    Plugin Author Dennis Ploetner

    (@realloc)

    Thank you so much for your donation to Greenpeace, Lucas!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Change the generated URLs’ is closed to new replies.