WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If one tries to load a theme template file directly, the following error message is displayed:

Fatal error: Call to undefined function get_header() in ...

and it goes on to list the full directory path to the wordpress install. This seems undesirable. How can I prevent it? Upon googling I found a suggestion to insert the following into wp-config.php:

@ini_set(‘display_errors’, 0);

Oddly, it did not work when I tested it.

Thank you!

share|improve this question
What do you mean "load a theme template file directly?" You're not supposed to load template files directly ... so what exactly are you trying to accomplish? – EAMann Apr 26 '11 at 19:29
Sorry. Let me clarify. There'd be no practical purpose for this, but if someone were mischievous and knew the path to your theme directory along with some common WP template file names, they could manually enter the uri for one and get this error message. And I guess what concerns me most is that the error outputs the site user name as a part of the file path. Thanks. – daxitude Apr 26 '11 at 19:37
ask your host how to disable error reporting for your particular server configuration. – Milo Apr 26 '11 at 20:18
@Milo it is more appropriate to disable error displaying rather than reporting. They should still be reported and logged. – Rarst Apr 26 '11 at 21:01

I define some variables used in my theme at the top of functions.php....one of them being

$press_here             = 'yes';

Then at the top of my template files I use

global $press_here;
if( !isset( $press_here ) )
    die('You don\'t have permission to view this page.');

Which then gives the error message I define there when being accessed directly, nothing more. (Thanks @t31os )

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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