Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

error_reporting(0);
@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

1 Answer 1

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

<?php
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

 
discard

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.