Most WordPress themes include a 404.php file.
If your does not it’s likely that adding a custom 404.php file will simply 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
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…
<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><ol>”;
}
?>
<li>
<label for=”s”><strong>Search</strong> for it:
<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>
Grab the text above from Dropbox for a quick copy/paste:
https://dl.dropboxusercontent.com/u/2698469/404.txt
Then test your 404 page by going to http://your+domain/junktext
Suffice it to say, having a poorly coded or broken 404 page can cause a great deal of hurt SEO-wise if you don’t do this right…
Enjoy!