• I run a multisite with subsites in different languages. How can I implement translations of my 404 page to match the language of the subpage?

    I use child themes, but they are not language specific. A child theme can be used for different languages.

    I have already customized title and text via add_filter / generate_404_title / generate_404_text.

    Thanks in advance!
    Marion

Viewing 5 replies - 1 through 5 (of 5 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    I wonder if a plugin like this would help?: https://www.ads-software.com/plugins/404page/

    That way you should just be able to translate the page you set as the 404 page.

    Let us know ??

    Thread Starter mlinhuberin

    (@mlinhuberin)

    The 404 page should appear in the language of the subsite just like all other sections of WordPress. Without the individual users or I have to take care of it.

    This should be possible without an extra plugin

    Hi,

    You can try this approach:

    add_filter( 'gettext', function( $text ) {
        if ( 'Oops! That page can’t be found.' === $text ) {
    		if( 'en_US' == get_locale() ){ return 'Your new text in english'; }
    		if( 'fr_FR' == get_locale() ){ return 'Your new text in french'; }
        }
    	if ( 'It looks like nothing was found at this location. Maybe try searching?' === $text ) {
            if( 'en_US' == get_locale() ){ return 'Your new text in english'; }
    		if( 'fr_FR' == get_locale() ){ return 'Your new text in french'; }
        }
        return $text;
    } );

    It gets the text and translates it depending on the get_locale() value.

    You can change/add more if( 'locale_LOCALE' == get_locale() ) conditions if you want to add more languages.

    You can use this as reference for the WordPress locale languages.
    https://wpastra.com/docs/complete-list-wordpress-locale-codes/

    Thread Starter mlinhuberin

    (@mlinhuberin)

    Thank you, that works!

    Thank you, that works!

    Glad it works for you. No problem. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘404 page in different languages’ is closed to new replies.