What is the error 404?
The error 404 is a message shows up if you click on a link that doesn’t work (anymore) or if you typed wrong Url. This is default in WordPress but some themes don’t come with a 404.php file.
Basic Error 404 Template
If you do not have default 404.php page, you can create it. Create a 404.php file with the below code..
<?php get_header(); ?>
<?php get_sidebars('left'); ?>
<h2>Error 404 - Page Not Found.</h2>
<?php get_sidebars('right'); ?>
<?php get_footer(); ?>
404 page with Search Form
Want to add search form to help users stick around instead of leaving. By this way visitors have the option of searching your site, even if lands on your 404 page. If you want to add search form for your 404 page, add the below code..
<?php get_header(); ?>
<?php get_sidebars('left'); ?>
<h2>Error 404 - Page Not Found.</h2>
<p>Search:</p>
<?php include(TEMPLATEPATH . "/searchform.php"); ?>
<?php get_sidebars('right'); ?>
<?php get_footer(); ?>
If you want to just redirect 404 page to home page then add the below code in 404.php
<?php
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: '.home_url( '/' ) );
?>
If you want to create a more dynamic error 404 page you can use this way so that the visitor only sees the brief error and, then gets redirected to your home page. This page can be made to be somewhat SEO friendly. For this you need to edit the header.php file of your template. Within the meta tags at the top of your header.php file add the below code ..
header.php
<?php
if (is_404()) {
*$redirectHome = get_option('home'); ?>
<?php echo $redirectHome; ?>
404.php
<?php get_header(); ?>
<?php get_sidebars('left'); ?>
<h1>Error 404 - File Not Found.</h1>
<h3>Please <a href="<?php bloginfo('home' Or 'template_url'); ?>" Click here</a> to return home page, or you can wait to be redirected in 15 seconds.</h3>
<?php get_sidebars('right'); ?>
<?php get_footer(); ?>
original
3 comments :
Interesting Post..good work..would like to read more on your blog.Please visit for more info on Property in NCR
Does a custom 404.php page work if you are using the default permalink structure (/?p=xxx)?
Convurgency
Is it really safe? I mean, if we use redirect, will google consider it as 404 or not? My blog with title supplier daging has some broken links in google web master
Post a Comment