Start with your theme's 404.php
Most WordPress themes include a 404.php file.
If yours doesn't, adding a custom 404.php file will likely work out of the box.
Below is my recommended coding for your 404.php file.
First, duplicate your index.php file, then rename as: 404.php
Add the 404 code
Note where the body text section is located within the file and simply replace with this example below. Change the descriptive text and styling as needed:
<div id="content" class="narrowcolumn">
<h2>My_Domain<br />Our goal is to help...</h2>
<p>Call us anytime, yada yada</p><br />
<?php
$s = preg_replace("/(.*)-(html|htm|php|asp|aspx)$/","$1",$wp_query->query_vars['name']);
$posts = query_posts('post_type=any&name='.$s);
$s = str_replace("-"," ",$s);
if (count($posts) == 0) {
$posts = query_posts('post_type=any&s='.$s);
}
if (count($posts) > 0) {
echo "<ol><li>";
echo "<p>Were you looking for one of the following articles?</p>";
echo "<ul>";
foreach ($posts as $post) {
echo '<li><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></li>';
}
echo "</ul>";
echo "<p></p></li>";
} else {
echo "<p></p>";
echo "<ol>";
}
?>
<li>
<label for="s"><strong>Search</strong> for it:</label>
<form style="display:inline;" action="<?php bloginfo('siteurl');?>">
<input type="text" value="<?php echo esc_attr($s); ?>" id="s" name="s"/> <input type="submit" value="Search"/>
</form>
</li>
</ol>
</div>
Test your 404 page
Note: this example uses query_posts(), which WordPress now discourages in modern themes. It still works on most sites, but test your 404 page after adding it by visiting a made-up address on your site (see the test URL below).
Then test your 404 page by going to http://your+domain/junktext
A poorly coded or broken 404 page can do a great deal of SEO damage if you don't get this right...
Enjoy!
