WordPress now has the ability to redirect old article links and titles to the new correct page, provided you’re using the latest version of WordPress, but what about 404 pages?
When a link is truly broken, and WordPress can’t already fix it automatically, you might as well just deal with the visit to your site as a 404 error page. There are plu gins out there that require manual input to redirect traffic, but is the broken link getting so much traffic that you need to go to all that trouble rather than adding content to your site. The article location will be re index in the search engines anyway, and you shouldn’t spend all your time being a perfectionist when it isn’t going to get you much of a ROI.
Since the visitor will land on a 404 error page that doesn’t monetize, or provide anything of interest for the visitor, it seems like a good idea to redirect, or forward, the visitor to the site’s homepage where they might find something of interest.
WordPress uses a standard 404.php landing page for every theme. The code usually looks something like this:
Error 404 – Not Found
To redirect visitors to your homepage, so they don’t land on a 404 error page, lose interest in your site and leave, we’ll start by creating a file to add to your theme templates.
Name the new file header404.php.
Copy the code from your header.php template file, and paste it into your new header.php file.
Now we’ll add the code we need to redirect our 404 error page visitors to our homepage.
At the very top of the file we’ll add this PHP code:
Change nerdgrind to your domain name.
We’ll also add a second line to be sure the web browser redirects in case the first line fails for some reason:
The code will look something like this in the header404.php file:
;
charset=" />
The rest of the code will come after the meta tag we are using to redirect, but overall this will be a standard header.php file with our new lines placed as you see them here.
Next we’ll need to edit the 404.php template file.
In order for the 404.php file to call our new header404.php file we’ll need to replace:
get_header();
with:
To see this script in action try typing in an article link on NerdGrind that doesn’t exist like:
http://www.nerdgrind.com/noarticle-here
With your 404 error pages redirecting your traffic to your homepage you can rest assured you won’t lose any traffic from broken links that land on a 404 error page. The best 404 error page is the one visitors don’t see.
Leave a Reply