No 404 on WordPress Blogs!

If you are like me, and you try out different things on your WordPress blogs, you are sometimes in a situation where you have a ton of redirects to do.

You could be changing permalink structure on an established blog, or you could be moving to new hosts, forgetting some posts or tags.

Whatever the reason, you have a few options regarding 404 errors. Not sure what that is?  What are 404 errors?

A 404 error is what occurs if you go to a post/page/tag/whatever, that no longer exists. Many WordPress Themes have a separate page for this situation, and you can tweak it accordingly. There is a problem, however, the link will still return a 404, and this will affect your ranking in the search engines.

Going through these manually and setting up redirects in your .htaccess or using a plugin such as Redirection (one of my favorite SEO WordPress Plugins) takes time, and you have to know what you are doing.

If you just want to make sure there are no leaking holes in your WordPress blog, that looses linkjuice for you, there is a very quick way for you to take care of this.

  • Go to the folder of your WordPress Theme
  • Does it have a file named “404.php”? If not, create one, if it does, consider using below code instead.
  • Open up the 404.php and fill in the following code:
<?php $url=bloginfo('url'); header("Location: $url ",TRUE,301); ?>

So, what is going on? Whenever a 404 error occurs, WordPress first tries to look in the WordPress Theme’s folder, to look for a 404.php file. If that does not exist, a 404 error is returned, and then an error page is displayed. This varies based on your server/host and .htaccess.

Read also  How to get plugin data programatically - get_plugin_data

You can also read automatic 301 redirects for spam pages.


This is the quick, fast and easy way to make a 301 redirect on all 404 pages on your WordPress blog. However, it does not register anything, and it only directs the “linkjuice” from the sites linking to you to your front page. If you wish to direct that linkjuice to some other place, you will have to edit the code.

Have fun 🙂

7 thoughts on “No 404 on WordPress Blogs!”

  1. Hmm…

    Did you guys get it working?

    I tired adding that code but it didnt’ work.

    I tried replacing the 404 page’s code with this but it fails to redirect and gives an error message.

    I tried adding it to the existing code and it also failed.

    I am pretty sure you’ve left some of the code out, such as the opening tag: ‘<?'

    Even adding that tag to the code won't get it to work though.

    Do I have to change any of that code to match the URL of my blog?

    I don't understand what I am doing wrong.

    Any additional info would be helpful thanks.

  2. OK, after a quick search I found a much easier way to do this. Simply add this to your 404 page:

    and change the URL to your blog’s front page.

    Simple and it works.

  3. I think you left out the opening ‘<?' tag.

    That code you gave won't work without it.

    Even if I add that tag it still doesn't work.

    Can you please post the full code needed to get this to redirect?



    Hi Dave

    I think your comment included some code that was cut after you commented?

  5. Danmark Bag Facaden

    on my blog i have my 404 error pages pointing to a overview over random feeds ( NyhedsLinks ), thats very usefull imo…

Leave a Comment

Your email address will not be published. Required fields are marked *