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 trialRachel Makovoz
5,005 PointsIndex 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
Treehouse Moderator 91,253 PointsHi 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
5,005 PointsHi, 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
Treehouse Moderator 91,253 Pointscould 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
5,005 Pointshere's the code for the 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
Treehouse Moderator 91,253 PointsI 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
5,005 PointsSorry, I realized my mistake. Was trying to run this on it's own without the Wordpress files.
Thanks so much for your help though!
Jonathan Grieve
Treehouse Moderator 91,253 PointsVery good! I'm glad you got it fixed! :)