How to create a custom 404 header for the theme WordPress - 404 Custom Header in WordPress Themes

WordPress is definitely the most customizable dynamic system we can create a presentation website, 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 functions WordPress.

In the tutorial today we will see how can we create a custom header for 404 (Not Found).

As a structure, most themes WordPress 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 404 pages from WordPress

First of all, we need to have FTP access to the site files and make sure that our theme WordPress are 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(); ?>

cu

 <?php include(TEMPLATEPATH . "/header_404.php");>

Save the file after you make the changes.

Now you have two headers on the theme WordPress. One common to all blog pages and one dedicated to 404 Not Found pages.

Passionate about technology, I enjoy writing on StealthSettings.com since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » net Surfing » How to create a custom 404 header for the theme WordPress - 404 Custom Header in WordPress Themes
Leave a Comment