Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is experiencing an issue where the Custom 404 Pro plugin, even though translated following the rules, links to the Italian error page instead of the English one when switching languages. This causes the settings for the Italian page to be deleted.
Solution:
Since the Custom 404 Pro plugin is not officially compatible with WPML, we recommend adding the following custom code to the

functions.php

file in your theme folder:

add_action('template_redirect', function() {
    global $wpdb;

    // Define the custom table name
    $table_options = $wpdb->prefix . 'custom_404_pro_options';

    // Get the stored 404 page ID from the custom table
    $page_id = $wpdb->get_var("SELECT value FROM $table_options WHERE name = 'mode_page'");

    if (is_404() && $page_id && function_exists('icl_object_id')) {
        $translated_page_id = icl_object_id($page_id, 'page', true);

        if ($translated_page_id && $translated_page_id != $page_id) {
            $translated_page_url = get_permalink($translated_page_id);
            
            if ($translated_page_url) {
                wp_redirect($translated_page_url, 302);
                exit;
            }
        }
    }
});

Please test this code in a staging environment before applying it to your live site. Additionally, consider contacting the plugin authors to encourage them to join our Go Global Program.

If this solution does not resolve your issue or seems outdated, please check our related known issues, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. If necessary, do not hesitate to open a new support ticket.

100% of people find this useful.

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.

This topic contains 2 replies, has 0 voices.

Last updated by Silvia Mancini 1 day, 6 hours ago.

Assisted by: Osama Mersal.

Author Posts
February 17, 2025 at 10:34 am #16713224

Silvia Mancini

Also as you know my situation, tell me if I have to open a new ticket but the plugin Custom 404 Pro even if i have translate it following the rules, once I am in the english version site and find an error page it links the italian page see the attached (italian setting CUSTOM 404) then I move into teh ENG tab on rigth top and select the Page not found page like this (english setting CUSTOM 404), changing the page to the English language causes me to delete the Italian...and I have NONE setting (none),
can you help me or I have to open a new ticket?

Am I doing something wrong?

Thank you Osama.
Silvia

February 17, 2025 at 10:58 am #16713341

Silvia Mancini

Here i attached some screenshot.
Thank you

none.png
italian setting CUSTOM 404.png
english setting CUSTOM 404.png
February 17, 2025 at 11:46 am #16713807

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

1) This plugin is not officially compatible with WPML. I found a workaround to fix the issue by adding the following code to the functions.php file inside your theme folder.

add_action('template_redirect', function() {
    global $wpdb;

    // Define the custom table name
    $table_options = $wpdb->prefix . 'custom_404_pro_options';

    // Get the stored 404 page ID from the custom table
    $page_id = $wpdb->get_var("SELECT value FROM $table_options WHERE name = 'mode_page'");

    if (is_404() && $page_id && function_exists('icl_object_id')) {
        $translated_page_id = icl_object_id($page_id, 'page', true);

        if ($translated_page_id && $translated_page_id != $page_id) {
            $translated_page_url = get_permalink($translated_page_id);
            
            if ($translated_page_url) {
                wp_redirect($translated_page_url, 302);
                exit;
            }
        }
    }
});

Please note that this custom code is a courtesy and is not officially supported by the WPML team. Please test it in a staging environment before applying it to a live site.

2) It would be great if you could contact the authors and urge them to join our Go Global Program.
You can find details about it here. (https://wpml.org/documentation/theme-compatibility/go-global-program/)

Best regards,
Osama

February 17, 2025 at 12:44 pm #16714283

Silvia Mancini

Hi Osama YOU ARE A WIZARD!!
Thank you so much it works fine and i have also texted the kCustom 404 pro' guy to make it global with you

fngers crossed.
You can close thit ticket

grazie mille