Call to undefined function get_header()

WordPress.

Used to get a lot of the above/following errors in my error log files…

Fatal error: Call to undefined function get_header() in /server_path/wp-content/themes/theme_folder/index.php on line 16

General response in most of the forums and blogs I found from a Google search seemed to based round people thinking it’s because the theme’s index.php file had been put into the root folder WordPress was installed in. When you know you haven’t done that and you look at the file in question, the theme index.php, and everything is as it should be you start wondering.

Well it’s all down to something or someone accessing the themes folder. So without the core functions of WordPress to tell it what get_header() should do it’ll throw up the error.

So if it’s a bot searching places it shouldn’t – it’ll probably be grabbing the link of your style.css then going up the directory tree to get to the theme folder – it’s time to fire up the robots.txt file. Put the following in it.


User-agent: *
Disallow: /wp-content/themes/

If you don’t already have one it should be in the root folder of the domain. Change the Disallow: path if your wp-content isn’t in the root directory.

It could also be someone checking out the folder of your theme, again looking at the style.css file then lopping off that end bit and getting the error message. And that error message will be showing the full path of your files from the server, kind of information you probably don’t want someone seeing.

So it’s probably best to stick in a bit of php to stop errors being displayed. You can find more about error reporting at php.net. Placing the error_reporting(0); before the get_header() call should stop anything showing up.


error_reporting(0);
get_header();

So no more reports about something you know about and can’t do much about.

Leave a Reply

Your email address will not be published.

Required fields *

This site uses Akismet to reduce spam. Learn how your comment data is processed.