For example I have in my theme folder named test-pages with some php web pages that display different message, in some part of process I want to pull with file_get_contents to get content of one page from that folder, but I can't do it, it just doesn't work, when I try to access directly to that page, I get 404 message like that pages doesn't exists.

How can I make this page visible to WordPress, so I can access it without getting 404?

Hope you understand me.


Move the template files out of the subdirectory, and put them in the Theme's root directory. Then, if you simply want to include the contents of those template files in other template files, simply call get_template_part( 'test-page-name.php' );.

If you insist on keeping these files in a subdirectory, you'll need to include them via locate_template().

|improve this answer|||||
  • <?php get_template_part('subfolder/test-page-name'); ?> also works, but I'm unsure if this is considered good practice or not. @Chip Bennett, care to weigh in on the pros/cons between the previous code and using <?php locate_template(); ?>? – cmegown Mar 2 '12 at 19:37
  • 1
    get_template_part() isn't really intended to search in subdirectories, though I think that might change in the future? In any case, locate_template() is the safer approach, as it will always work, and is intended to search in subdirectories. The advantage of using get_template_part() is that it's a bit more simple/straightforward. – Chip Bennett Mar 2 '12 at 19:48
  • @Chip Bennett Thank you, I totally forgot on locate_template. Thank you. – user1147 Mar 3 '12 at 3:56

The solution is here.

Simply go into the page template you want to edit and add this at the very top:

    Template Name: Your template name goes here

When you go into the admin area and edit the page you want, a dropdown list of page templates will appear in the right column that you can choose from.

Edit: If you have already done what I described above, and the problem persists, you might have a .htaccess issue. Another possibility is that you aren't referencing the file correctly, so double check your declarations to make sure they are producing the correct file path and file name. Hope this helps you out!

|improve this answer|||||
  • Also, pull the template file out of the subdirectory, and put it in the Theme's root directory. – Chip Bennett Mar 2 '12 at 17:35

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.