Support » Plugin: Multisite Language Switcher » Translatable CPT slug generates wrong URLs in the switcher

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

    (@realloc)

    Hello,

    MSLS should save the translated strings alone but there are some scenarios when this can’t be done.

    You can use a filter for this:

    https://gist.github.com/lloc/5f922fc770d818365992#file-msls_options_get_permalink-php

    Read on here too:

    http://msls.co/hooks-filters-and-actions/

    Cheers.
    Dennis

    Hi there,

    thanks for your reply! So I tried the msls_options_get_permalink filter.

    I tried pasting it in my theme functions.php file, but it breaks the website ( I get a white screen in the dashboard).

    Then I copy/paste it in my CPT plugin, but it only works from English to Italian:

    function my_msls_options_get_permalink( $url, $language ) {
        
        if ( 'it_IT' == $language ) {
            $url = str_replace( '/product/', '/prodotto/', $url );
        }
        return $url;
        
    }
    add_filter( 'msls_options_get_permalink', 'my_msls_options_get_permalink', 10, 2 );

    I even tried this with no better result:

    function my_msls_options_get_permalink( $url, $language ) {
        
        if ( 'it_IT' == $language ) {
            $url = str_replace( '/product/', '/prodotto/', $url );
        } elseif ( 'en_US' == $language ) {
            $url = str_replace( '/prodotto/', '/product/', $url );
        }
        return $url;
        
    }
    add_filter( 'msls_options_get_permalink', 'my_msls_options_get_permalink', 10, 2 );

    In the MSLS italian setting I now noticed a Rewrite rule: https://imgur.com/a/yiyRTBw

    I’m pretty sure Prodotti slug was product before.

    Any suggestion on what could interfere?

    Thanks again!

    Simone

    Plugin Author Dennis Ploetner

    (@realloc)

    It should also work in the functions.php. Of course – a plugin that you control would probably be a safer place for the snippet.

    I guess that the locale of the english webseite is not ‘en_US’ … just try this to confirm that:

    function my_msls_options_get_permalink( $url, $language ) {   
        if ( 'it_IT' == $language ) {
            $url = str_replace( '/product/', '/prodotto/', $url );
        } else {
            $url = str_replace( '/prodotto/', '/product/', $url );
        }
        return $url;
    }
    add_filter( 'msls_options_get_permalink', 'my_msls_options_get_permalink', 10, 2 );

    Hi Dennis,

    thank you again! I suspected the same and already tried that solution (it’s the one live now). That’s so weird, I usually don’t have such problem. I’m probably missing something really simple.

    Is there a way to reset the options of the plugin, and start clean without loosing the linking between pages?

    Thanks a lot,

    Simone

    Plugin Author Dennis Ploetner

    (@realloc)

    The plugin writes just its options (when you save settings in the dashboard). So this is nothing to clean.

    Very often it needs just a refresh in the permalinks to avoid this kind of strange behaviour in a WordPress website.

    Apparantly saving the permalinks pages several times wasn’t enough.

    I used flush_rewrite_rules() and did the trick.

    Thanks again for your support!

    Simone

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.