This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Tagged: Not WPML issue
This topic contains 3 replies, has 2 voices.
Last updated by mariaA-45 1 year, 11 months ago.
Assisted by: Eran Helzer.
Author | Posts |
---|---|
July 9, 2023 at 10:16 am #13972553 | |
mariaA-45 |
Tell us what you are trying to do? Example What is the link to your site? |
July 9, 2023 at 12:24 pm #13972733 | |
Eran Helzer Supporter
Languages: English (English ) Hebrew (עברית ) Timezone: Asia/Jerusalem (GMT+03:00) |
Hi, Using WPML there is no way to configure different 404 pages per language, according to the url, however that can be achieved with some little custom code. For example, you can use the WPML action `wpml_switch_language` in your 404 page template to switch languages based on any custom login you want, for example urls containing '/en/'. A general example of this idea is adding this code to the 404.php file (TwentyTwentyOne theme): if (str_contains($_SERVER['REQUEST_URI'], '/es/')) { do_action( 'wpml_switch_language', 'es' ); } Take into account that this does not mean we take responsibility for this custom code and will not provide support for it, this is merely a friendly suggestion on one way you can achieve what you want. Additionally, you can make use of our contractor program to hire an experienced developer to do this job, here: Please tell me if this answers your question or if you have any more related to this topic. |
July 9, 2023 at 7:49 pm #13973469 | |
mariaA-45 |
Hi Eran, thanks for your response. You misunderstood my question (a bit), but your response was golden anyway. Thanks! I use the Kadence Theme and thus a Kadence Element to customize the content of my 404 page. Inside the Kadence Element, I wrap that custom content in a vanilla-Wordpress-reusable-Gutenberg-block to be able to use WPMLs Automatic Translation Editor to translate my custom 404 page. This way, I already have a Danish and a English 404 page. Nothing magic. function bofy_pre_handle_404($preempt, $wp_query) { if ( !str_contains($_SERVER['REQUEST_URI'], '/en/') && !str_contains($_SERVER['REQUEST_URI'], '/da/') ) { do_action( 'wpml_switch_language', 'en' ); } return $preempt; } add_filter( "pre_handle_404", "bofy_pre_handle_404", 10, 2 ); The code simply checks, whether the request URL that provoked the 404 contains a language-specific subfolder ("/da/" or "/en/") and, if not, forces English as language. The rest is default 404-handling. Thanks again, Eran, for pointing my nose! Best, |