WordPress is definitely the most customizable dynamic system we can create presentation website, a blog or even one shop. It offers thousands of themes (also called templates or WordPress Themes) and modules (WordPress Plugins) through which we can create a website as we wish without knowing PHP, HTML or graphic editing code.
But there are also some situations when we need to get out of the “settings default”Offered by WordPress and make changes. These often involve changes in WordPress features.
In the tutorial today we will see how can we create a custom header for 404 (Not Found).
As a structure, most WordPress themes are composed of: index.php (first file, footer.php (bottom), sidebar.php (side edges), single.php (article page), header.php (top). The upper and lower ones, respectively header.php si footer.php are common to all other content files. More precisely, if we make a change to the code in header.php, it will be present on absolutely all pages of the blog / website. Even in the 404 error, intended for non-existent content / non-existent pages.
Most traffic, advertising, status website tracking codes are usually placed in header.php, but we do not always want these codes to be active on 404 pages. To avoid this situation, the simplest solution is to define a separate header for 404 error pages.
How to create a custom header for WordPress 404 pages
First of all, we need to have FTP access to the site's files and make sure that our WordPress theme has declared a dedicated file for 404 pages. This is found in the theme folder (wp-content / themes / name) 404.php. If you do not have this file present in the current theme folder, you can copy the one from the Twenty Thirteen theme.
After we had the 404.php file in the current theme folder, we do one duplicate to the header.php file which we will call "header_404.php".
The next step is to set this file as the header for the 404.php file. We do this by replacing the line:
<?php get_header(); ?>
<?php include(TEMPLATEPATH . "/header_404.php");>
Save the file after you make the changes.
Now you'll have two headers in the WordPress theme. One common to all blog pages and one dedicated to 404 Not Found.