0

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?

7
  • 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.
    – fuxia
    Jul 30 '12 at 16:24
1

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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