When I remove get_header() from 404 page, my css doesnt work.

   * The template for displaying 404 pages (Not Found)
   * @package WordPress
   * @subpackage Twenty_Fourteen
   * @since Twenty Fourteen 1.0


<div class="page-content">
    <h1 class="page-title"><?php _e( 'Not Found', 'twentyfourteen' ); ?></h1>
    <p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'twentyfourteen' ); ?></p>


  .page-content {
   max-width: 300px;
   margin: 0 auto;
   text-align: center;

 .page-title {
  color: red;
  • Why would you want to remove get_header()? Your CSS file is linked in this header, so it makes sense that it is no longer working when you remove this piece of code. Commented Oct 27, 2015 at 14:20
  • I have link my stylesheet to function.php. wp_enqueue_style('style', get_stylesheet_uri()); Commented Oct 27, 2015 at 14:21
  • Because I don't want the logo and navigation for my 404 page. Commented Oct 27, 2015 at 14:22
  • Then either write a different header for your 404 page, or include all the things that are in the header that are required for a working page, such as your html,head,body directly in to the 404 page template. Your "header" that is associated with get_header() includes way more than just your navigation. Check your header.php file to see what is included. Commented Oct 27, 2015 at 14:29

2 Answers 2


Of course it doesn't. When you remove get_header() you also remove the code that loads the CSS files, not to mention that you remove large blocks of necessary HTML markup. The template you've posted above is very, very broken.

You've also left out get_footer() which will most likely leave your markup broken as well.

Instead of leaving out get_header() use it with an optional argument to load a truncated header file for your 404 page:


Includes the header.php template file from your current theme's directory. If a name is specified then a specialised header header-{name}.php will be included.

If the theme contains no header.php file then the header from the default theme wp-includes/theme-compat/header.php will be included.

For example (from the Codex):

if ( is_home() ) :
    get_header( 'home' );
elseif ( is_404() ) :
    get_header( '404' );
else :

In your template, you only need get_header( '404' ); plus a PHP file named header-404.php containing whatever you want to display.

  • Check my below comment. I have my stylesheet in function php Commented Oct 27, 2015 at 14:35
  • Exactly where/how do you think the wp_enqueue_scripts hook fires?
    – s_ha_dum
    Commented Oct 27, 2015 at 14:37
  • 1
    I'll give you a hint: wp_enqueue_script fires on wp_head, which is fired by the wp_head() function which is in the header file that you've left out.
    – s_ha_dum
    Commented Oct 27, 2015 at 14:41

Minimum template structure is:

1) get_header()

2) get_footer()

You can not touch this functions, this is a heart of each template/page/single/category...

  • 1
    Using get_header and get_footer are not required, you can call wp_head and wp_footer directly inside a template file.
    – Milo
    Commented Oct 28, 2015 at 21:16
  • @Milo It is a little bit wrong way to do that ;)
    – vol4ikman
    Commented Oct 28, 2015 at 21:19
  • It's not at all wrong. Only index.php and style.css are required.
    – Milo
    Commented Oct 28, 2015 at 21:24
  • @Milo OK, and what you put inside index.php? I am not talking about template hierarchy, I am talking about template functions :)
    – vol4ikman
    Commented Oct 28, 2015 at 21:26
  • get_header and get_footer load templates. As I said in my first comment, you only need wp_head and wp_footer.
    – Milo
    Commented Oct 28, 2015 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.