Hi there. I’m looking a way to make Custom 404 to work with WPML. I’ve tried all existing solutions at the KB and Forums. The best I got so far was from this topic:
I’ve changed all ocurrences from ‘x_custom_404’ to ‘tco_custom_404’ (also the one with capital letters) as the plugin has changed. The translated pages content is being loaded, but only raw-text without formatting, links, images, etcetera.
If you try to reach per example “dude”(a non-existing page). Try to go to it and you’ll see the output is the redirected page’s raw-text. Then the correct translations:
https://flynet.cloud/en/dude/ --> translation --> https://flynet.cloud/en/not-found/
https://flynet.cloud/fr/dude/ --> translation --> https://flynet.cloud/fr/pas-trouve/
https://flynet.cloud/it/dude/ --> translation --> https://flynet.cloud/it/non-trovato/
https://flynet.cloud/es/dude/ --> translation --> https://flynet.cloud/es/no-encontrado/
https://flynet.cloud/ca/dude/ --> translation --> https://flynet.cloud/ca/no-trobat/
https://flynet.cloud/pt-br/dude/ --> translation --> https://flynet.cloud/pt-br/nao-encontrado/
The translated pages (‘pas-trouve’, ‘non-trovato’, ‘no-encontrado’, ‘no-trobat’ and ‘nao-encontrado’) are the translations of the ‘not-found’ page. When you try an unexisting page, the pluting is outputting the raw text, but not the formatting, css, links…
I have on /wp-content/plugins/tco-custom-404/views/site/custom-404.php by now:
<?php
// =============================================================================
// VIEWS/SITE/CUSTOM-404.PHP
// -----------------------------------------------------------------------------
// Plugin site output.
// =============================================================================
// =============================================================================
// TABLE OF CONTENTS
// -----------------------------------------------------------------------------
// 01. Output
// =============================================================================
// Output
// =============================================================================
function tco_custom_404_filter_template( $template ) {
require( TCO_CUSTOM_404_PATH . '/functions/options.php' );
if ( ! isset( $tco_custom_404_enable ) || ! $tco_custom_404_enable ) {
return $template;
}
global $sitepress;
if ( function_exists( 'icl_object_id' ) && is_callable( array( $sitepress, 'get_current_language' ) ) ) {
$custom_404_post = get_post( icl_object_id( $tco_custom_404_entry_include, 'page', false, $sitepress->get_current_language() ) );
}
else {
$custom_404_post = get_post( (int) $tco_custom_404_entry_include );
}
if ( ! is_a( $custom_404_post, 'WP_Post' ) ) {
return $template;
}
GLOBAL $wp_query;
GLOBAL $post;
$post = $custom_404_post;
$wp_query->posts = array( $post );
$wp_query->queried_object_id = $post->ID;
$wp_query->queried_object = $post;
$wp_query->post_count = 1;
$wp_query->found_posts = 1;
$wp_query->max_num_pages = 0;
$wp_query->is_404 = false;
$wp_query->is_page = true;
return get_page_template();
}
add_filter( '404_template', 'tco_custom_404_filter_template' );
I know I’m not so far from having it working, but I don’t know what should be done.
Could some of our support heroes to find-out a solution for that?
Thank you once more and best regards!