Custom 404 + WPML

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!

Hi Fabio,

Thanks for reaching out.

That fix wasn’t related to URL. It was for 404 page not picking up the template/page required for translated 404. Unfortunately, changing the URL structure is not part of the plugin which would require custom development.

It’s either URL redirect or URL rewrite customization, I recommend contacting a developer.

Thanks!

Is sad that Themeco is less and less developing for WPML. The themes were considered compatible but now they don’t appear on WPML’s compatibility list… The world speaks an enormous amount of languages…

Hello Fabio,

I have inform our developers that Custom 404 needs WPML support. Once they’ll have it fixed, it will be updated and rolled out in the next release update cycle of the plugin.

Thank you for your understanding.

1 Like

That’s a much more cooooool answer, thank you! Hope it comes soon! Please add WPML support to everything (Custom 404 and Under Construction are urgent): nowadays it’s a must. Cheers!

1 Like

No problem.
If you need anything else we can help you with, don’t hesitate to open another thread.

Nothing for this moment thanks. Please post here or let me know if/when WPML support starts to be implemented more seriously (including the full translation of X, Pro and all Extensions). And let me know if I can help in anyway on these tasks, I’m good on localization/translation. Cheers.

Sure thing.
Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.