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.

in default theme files i.e. index.php, single.php etc. i can use all the WP functions normally. But if i create a new theme file, for example custom-file.php and place it in the theme folder, i don't have access to default WP functions like get_header, etc...

Is there anything that could be included in custom files to make them recognized by WP as a part of the theme?

share|improve this question
    
How are you including (executing) the file? –  Richard Jul 30 '12 at 16:05
    
i should be able to access the file directly, some code in there that must run on direct access - www.example.com/wp-content/themes/my-theme/custom-file.php –  user18716 Jul 30 '12 at 16:10
    
EDIT: damn, i just tried it, even if i try to access a default wp theme file directly it won't work, my fail... looks like there is no way to do this. –  user18716 Jul 30 '12 at 16:16
    
Ok looke like i found it, all you need to do is to include "wp-load.php" file from the WP root folder in your custom file and then you can access your custom file directly as well (www.example.com/wp-content/themes/my-theme/custom-file.php ) –  user18716 Jul 30 '12 at 16:22
3  
Don’t do that. Register an address for the file, avoid to load wp-load.php. –  toscho Jul 30 '12 at 16:24
show 2 more comments

1 Answer

Add a PHP comment to the top of your file, making it a Template:

<?php /* Template Name: Whatever */

//your code here

?>

Then create a new page with your new template as page template. Publish, then you will be able to access the file through the pages permalink.

Kind of quick and dirty, but it worked for me...

share|improve this answer
add comment

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.