Smart page 404

WordPress automatically manages the page that is displayed when a user provides the URL of a page that does not exist.

In fact, it is enough to place the 404.php file with other theme files so that the contents of this file are displayed in the event of a URL error.

Most often, the visitor is presented with a banal and muzzle message:

Page not found.

It's not very noticeable. In the slightest case, offer him other pages to view or, even better, find the article that most resembles what he was looking for. For this, one condition is that the links are significant, made from keywords, it was impossible to guess what the Internet user is looking for when he dials the article number!
Most webmasters using Wordpress configure permalians in the dashboard with the% postname% command.

Page code 404

The structure of the page is minimal error, so the contents of the 404.php file are as follows:

<?php get_header(); ?>
<div id="content">
    <h2>Error 404 - Not Found</h2>
</div>
<?php 
   get_sidebar();
   get_footer(); 
?>

This is the default WordPress theme file, in its purest form.

It would be very easy to add a list of recent tickets so that the visitor who comes to the page is more inclined to continue reading than to leave the site.

<div id="content">
<h2>Error 404 - Not Found</h2>
<h2>Derniers articles</h2>
<ul>
<?php wp_get_archives('type=postbypost&limit=10'); ?>
</ul>
</div>

It can be seen that it is enough to add a few lines ...

Search for similar pages

From the words contained in the web-based URL, you can also search the ticket titles to find the one that would be closest to what is requested.

Note that Wordpress itself does the recovery of erroneous URLs by taking the first words and finding an article starting with these words. The proposed algorithm will work in the event of a WordPress crash .

A query is created with the following algorithm:

$com = "";
foreach($keywords as $word)
{
if(strlen($word < 5) && $count > 3) continue;

if($com != "") $com .= " AND ";
$com .= "(post_title LIKE '%$word%')";
} $com .= " AND post_type = 'post'"; $command="SELECT post_title, post_name FROM $table WHERE $com";

- Short words are excluded if the URL does not contain only two words.
- This creates a WHERE clause consisting of an AND series that compares words in article headers to words in a URL.
-Revise records attached by post_type=post condition are deleted.

The final request will take the following form:

SELECT post_title, post_name FROM $table WHERE (post_title LIKE '%mot1%') AND 
(post_title LIKE '%mot2%') ...etc... AND
post_type = 'post"
The list of links generated by the <a> tag is created from both the list of names and the list of URLs.

Use related plugins

This algorithm could be developed to further increase its relevance. But instead of remaking the world, why don't you use a plugin from "correspondence," posts on a similar topic?

If there are no tags for the search item, a list is created at the specified URL.

$url=$_SERVER{'REQUEST_URI'};
$url = str_replace("%20", " ", $url);
$url = strtolower($url);
$keywords=split('[/.-_ ,]',$url);

Keywords are elements of the $ keywords table. This list of tags interacts with plugin functions.

Plugin from "related":

Download page 404

If you want to keep the classic misspelled page, you can try to make it enjoyable for the visitor...

Not found Japon

Page not found in Japanese style