Home / Marketing Videos / WordPress 404: Page Not Found? Try these links…

WordPress 404: Page Not Found? Try these links…

I really appreciate sites that intelligently try to redirect you to the pages you may be looking for. Let’s say I’m looking for ajax information on a given site, I usually simply try to use the word in the URL to see what happens.

On Microsoft, see what happens:
Helpful, huh?

Now try it on Yahoo!:

How about our hero, Google:
C’mon! You’re a freakin’ search engine for heaven’s sake!

How difficult is it to simply take the words in the URL and come up with some search results that might guide you to the right page? It’s not so difficult!!! In fact, I programmed it into my site tonight in about an hour:

404 Related Posts

I simply used the same logic that the related posts widget code utilizes and applied it on the 404 not found page. It scores the content based on the keywords (there can be more than one) pulled from your URL. Your theme will need to support a 404 page in order to implement it. Also, this one is built for my theme, you may have to make some modifications.

Download the 404.php page here. Feel free to use it where ever you’d like! It does require that you have the Related Posts plugin!

About Douglas Karr

Douglas Karr is the founder of The Marketing Technology Blog. Doug is the CMO of CircuPress and CEO of DK New Media, an agency specializing in assisting marketing technology companies with their inbound marketing - leveraging social media, blogging, search engine optimization, pay per click and public relations. Their clients include Angie's List, GoDaddy, Mindjet and many more. Douglas is also the author of Corporate Blogging for Dummies.

Check Also

Retail Trends

5 Retail Trends for 2015 Every Marketer Should Know

Two-thirds of consumers now shop across devices, making multi-touch attribution and omnichannel marketing key to …


  1. Thanks for posting this Doug. I had thought of doing something similar to this, but just hadn’t gotten around to coding it yet. Now you’ve made my job much easier :)

  2. Great idea! I added it to my site. A couple notes though:

    1) If you don’t have the related posts plugin, you probably haven’t created the necessary fulltext index required by the SQL code here. Run the following against your WP database at a MySQL prompt:

    ALTER TABLE `wp_posts` ADD FULLTEXT `post_related` (`post_name` ,`post_content`);

    2) Doug, you might want to revise the code as it’s vulnerable to SQL injection and cross-site scripting attacks. It’s as simple as using mysql_escape_string() against $keyword in the SQL statement and htmlspecialchars() against $keyword when displaying it on the page. You can see the changes I made at http://blog.olonoh.com/downloads/404.zip (modified for my theme).

    Try http://www.douglaskarr.com/ajax to see what I mean.

  3. Whoops, that sample URL didn’t come through. Basically add any opening HTML tag at the end of the URL to test. e.g. a BLINK tag.

  4. Thanks Ade! I updated my page AND the download page. Could you do my readers a favor and write a post on SQL injection /cross-site scritping attacks? I’d like to learn more about how it would have been done in this case and how exactly it works. I’m a little bit ignorant of the topic.

    That’s why I’m a hack and you’re a programmer!

    Thanks, Again!

  5. That’s a good idea for a blog post. I think I’ll work on something like that.

    In the meantime, here’s what Wikipedia has to say:


  6. For anyone who is interested, I put together a Beginner’s Guide to Understanding SQL Injection.

  7. Tonight I noticed that there is a related posts plugin that also has 404 support here:

  8. Thank you, Doug. This is the most useful thing to do with a 404 page I’ve seen.

  9. Thanks, Rick! I think it’s helpful, too… especially if you’ve moved some posts or deleted them.

  10. Thanks, I downloaded your code, as I’ve got a couple places where I can use this. And, and for the record. Google is not a search engine, they’re actually an advertising company. So, you can’t really expect them to develop an intelligent 404 page 😉

Leave a Reply