2

So I've got to edit my 404 page. Since my client's website has 5 languages, I'd like to let him edit and translate the 404 page by himself, with normal WordPress editor. Also, we're currently using Polylang as the localization plugin.

Is there a way to have the theme's 404.php as a regular page?

I've tried to create a page and then assign it to the 404 template via template name, but it doesn't work, because it seems that $post is not available inside the template, so I cannot write contents.

1

Found a way.

  • Create a regular page for 404 content, say 'Page not found';

  • In your 404.php file, get that page data and then write down your content or whatever...

For example:

$page = get_page_by_title("Page not found");  
if($page) echo apply_filters('the_content',$page->post_content);

Obviously, you can do a lot more...

0

First of all, you should avoid Error 404 on your sites absolutely and unconditionally.

Second, you can use a text widget somewhere on the 404.php page. Put the following code into the functions.php to register a sidebar to put the widget in:

<?php

function error_404_widget_init() {

    register_sidebar( array(
        'name'          => 'Error 404 widget',
        'id'            => 'error_404',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="rounded">',
        'after_title'   => '</h2>',
    ) );

}
add_action( 'widgets_init', 'error_404_widget_init' );

And add the following into 404.php template file, in the place you like:

<?php
dynamic_sidebar( 'error_404' );

After that you'll be able to add the widget to the sidebar and specify a text for each language using Polylang's default functionality.

1
  • I tried before finding my own solution, but it seems there are problems with the theme customizer about widgets for 404. I think some bug. Anyway I think using the content of a custom page is far more a versatile way :) – Luca Reghellin Dec 14 '16 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.