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

Robbie Thomas
Robbie Thomas
31,093 Points

Getting a Fatal Error after finishing 'Create the Basic WordPress Theme Files'

Got the said objective done and followed all rules precisely, however, Zac Gordon's theme works and I get this:

Fatal error: Call to undefined function get_header() in C:\xampp\htdocs\BootStrap-to-wp\index.php on line 1

I did put the php header tag in right. The funny thing is, I made a second copy and uploaded it to my server via SiteGround.com and it works over there, but not on my local host.

Here is the one theme working on SiteGround: http://robbeewrite.com/lifetheband/

My guess is that I have other themes in the SiteGround WP that are included with the site, but not on my localhost, is that a possibility?

4 Answers

Brian Hayes
Brian Hayes
20,986 Points

Debug mode is not an Xampp function, but one that is from WordPress. Here is the Codex entry that goes over it.

you may have improperly pasted your code it seems... if you're syntax for the line that calls get_header() is exactly:

get_header(); ?

then you seem to have a syntax error in that there is not opening or closing of php tags to call the function in the first place... however this could be because you improperly pasted your code into the post. I'm pretty sure that's the case since the function call was picked up by by the debugger and if the function wasnt inside php tags i dont think it would be read at all.

but just in case,

<?php get_header(); ?>

<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
  <div class="container">
    <h1>Hello, world!</h1>
    <p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
    <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more &raquo;</a></p>
  </div>
</div>

something like that should properly call the function. Now if the function isn't being properly called currently, you should be missing the code in your header.php in what is displayed on the site. This should be you're navigation, or at least the static navigation if you haven't gotten as far as creating the necessary menu walkers and dynamic code for it yet.

Brian Hayes
Brian Hayes
20,986 Points

Without actually seeing your code, it's hard to know what exactly is wrong.

Now, you may be using your local install in Debug mode which could be why that error shows up and looks to break your site, while on your live site debug mode is off and while the error is still there, it doesnt break the site because it's not reported and isnt a fatal enough error to stop the site from working.

Point is that with Debug mode on in the WordPress config file, errors that don't normally break a website will in fact break the site and display an error. This is simply for development purposes, which is why it would be on in your local install, and not on your live server.

"call to an undefined function" means that you called the function get_header() but have yet to actually create a function called get_header(). At least that's what the debugger thinks anyway.

Considering that this is a WordPress core function that you're calling, I don't know exactly why you are getting this error. It could be that there is something wrong with your header.php file, or there could be a problem with the WordPress core templates function file wp-includes/general-template.php.

I can sit here and make guesses all day, but I'd have to see you're theme code to know.

Robbie Thomas
Robbie Thomas
31,093 Points

Yes, I forgot to add code, here is my code for the index.php. I only put the first ten lines, the problem is with the first line:

<?php get_header(); ?>

<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
  <div class="container">
    <h1>Hello, world!</h1>
    <p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
    <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more &raquo;</a></p>
  </div>
</div>

I'll also look into debug mode with Xampp.

Robbie Thomas
Robbie Thomas
31,093 Points

Well, I did the rest of the Bootstrap to WP via the Siteground Code Editor. It isn't as helpful and color coded as Sublime Text but it worked out well. Thanks for the help.