WordPress is definitely the most customized dynamic system that we can create an presentation website, and blog or even one Magazine online. Offers thousands of themes (also called templates or WordPress Themes) if module (WordPress Plugins) through which we can create a website as we want, without having PHP code knowledge, HTML or graphic editing.
But there are some situations when we need to get out of “Default settings” offered by WordPress and make changes. They most often involve changes in WordPress functions.
In today's tutorial we will see How can we create a personalized header for pages 404 (Not Found).
As the structure, most of the WordPress themes are composed of: index.php (first file, footer.php (bottom), sidebar.php (side edges), single.php (article page), header.php (top). The sheets related to the upper and lower side, respectively header.php si footer.php They are common for all other content files. Specifically, if we make a change in the code in header.php, this will be present on all the pages of the blog / website. Even in those of error 404, intended for non -existent content / non -existent pages.
Most traffic tracking codes, advertising, website status are usually placed in header.php, but we would not always want these codes to be active in pages 404. To avoid this situation, the simplest solution is to define a separate header for Error pages 404.
How we create a personalized header for WordPress Pages 404
First of all, we must have FTP access to the site files and make sure that our WordPress theme has declared a dedicated file for pages 404. You can find it in the theme folder (WP-Content/Themes/Name_Tema) with the name 404.php. In case you do not have this file present in the folder of the current theme, you can copy the one on the Twenty Thirteen theme.
After we had file 404.php in the current basis folder, we make a duplicate to the header.php file that we will call “header_404.php“.
The next step is to set this file as a header for file 404.php. We do this by replacing the line:
<?php get_header(); ?>
with
<?php include(TEMPLATEPATH . "/header_404.php");>
Save the file after making the changes.
Now you will have two headers in the theme of WordPress. A common one for all the pages of the blog and one dedicated to pages 404 not found.