Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development WordPress Header and Footer Templates Porting existing headers and footers into WordPress

Rachel Makovoz
Rachel Makovoz
5,005 Points

Index File not running, Fatal Error

Hi, I tried running the code from this class so far but when I try to view the index file I get this error.

Fatal error: Uncaught Error: Call to undefined function get_header() in C:\xampp\htdocs\snowberry\index.php:1 Stack trace: #0 {main} thrown in C:\xampp\htdocs\snowberry\index.php on line 1

This is the code that it is in my index.php file:

<?php get_header(); ?>
<section class="row">
    <div class="small-12 columns text-center">
        <div class="leader">
            <h1> Etiam Mollis Sit Gratt Spore</h1>
            <p>Macenas sed diam egat risus varius blandit sit amet non magna. Millam quis amigo let iohf hoir.</p>
        </div>
    </div>
</section>


<?php get_footer(); ?>

Please let me know what may be causing this.

Thanks!

4 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Rachel,

Can you confirm if you have a header.php and footer.php file for your theme? It's likely a missing file or a problem in that file that is causing this error! :-)

Rachel Makovoz
Rachel Makovoz
5,005 Points

Hi, yes I do.

And I just tested it with the theme file from the course and got the same error. Could it be there is something wrong with my localhost?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

could you post the code for your header.php file? I don't see a problem with the index.php file itself.

Remember all files pertaining to your specific theme all go in the main directory for that theme. Get header exists mainly to call the header.php file

Rachel Makovoz
Rachel Makovoz
5,005 Points

here's the code for the header.php

header.php
<!doctype html>
<html class="no-js" lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title><?php wp_title( '|', true, 'right' ); bloginfo( 'name' ); ?></title>

    <?php wp_head(); ?>

  </head>

  <body <?php  body_class(); ?>>
    <header class="row no-max pad main">
  <h1><a class='current' href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1>
  <a href="" class="nav-toggle"><span></span>Menu</a>
  <nav>
    <h1 class="open"><a class='current' href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1>

    <?php 

      $defaults = array(
        'container' => false,
        'theme_location'  => 'primary-menu',
        'menu_class'  => 'no-bullet'
      );

      wp_nav_menu( $defaults );

    ?>

  </nav>
</header>

And yes, it is located in the main directory.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

I have one or 2 things to suggest, although I'm not sure if they'll help you get rid of the error. I still think there may be a error somewhere in your project structure but it's hard to know without being able to look at your project directories. From where I'm sitting it should work.

Try including the body_class() method as a class attribute of body.

<?php
<body class=" <?php body_class(); ?"> 

Again, I'm doing a bit of guesswork here but it might add some classes behind the scenes that'll start to make things tick.

Rachel Makovoz
Rachel Makovoz
5,005 Points

Sorry, I realized my mistake. Was trying to run this on it's own without the Wordpress files.

Thanks so much for your help though!