I'm not sure WordPress was build for this, but this is what I'm trying to achieve:

  • I want to make a specific URL inside wordpress accessible, for example www.example.com/some-template .
  • This specific URL should be editable from a php file, part of an existing wordpress theme I'm working on, something like some-template.php)
  • This is the tricky part: I don't want wordpress users to be able to see or use this template from the custom templates dropdown menu when editing a page. I don't want a specific page to exist in order for this to work. This template should work without any page (I'm not interested in creating a page and hiding it, or hiding the template).

The reason I'm trying to do this, is that I want to have a specific template that pieces together a few pages and menus from wordpress and creates some kind of a 'custom view' which is pulled every few hours to another site. It's all part of a bigger picture (the details are not that important).

While searching, I only found out that it's possible to create custom templates for at least one page, but then that page must exist in wordpress for the template to work.

Does anyone have an idea of how to achieve this?

2 Answers 2


You may use template_redirect action:

add_action( 'template_redirect', 'wpse131387_template_redirect' );
function wpse131387_template_redirect( ){
    if ($_SERVER['REQUEST_URI'] == '/some-template') {
        global $wp_query;
        $wp_query->is_404 = false;
        include(dirname(__FILE__) . '/some-template.php');
  • Thanks. I ended up with using fischi's solution although I believe your could work as well. Jan 31, 2014 at 10:41
  • @ShaharDekel Welcome! With this solution you keep everything in your theme and there is no need to touch .htaccess.
    – Parham
    Jan 31, 2014 at 11:01
  • 1
    Use the filter template_include instead: markjaquith.wordpress.com/2014/02/19/… Nov 9, 2016 at 22:05
  • I'm not sure, But after some tests, I think template_include effects performance.
    – Mohsen35
    Jun 17, 2022 at 2:00

You could do it the very simple way, putting your file some-template.php in the root directory of your WordPress install.

Adding this to your .htaccess will use the some-template.php for the url www.mysite.com/some-template

RewriteRule ^some-template$ ./some-template.php$1  

In your some-template.php you load WordPress, including wp-load.php

//all your custom goodies

Now you have access to all WordPress functions, and you do not need to have a page in the database.

Please be aware that if someone creates a page some-template, you may get an error, as the page is not visible due to your custom file.

  • Your RewriteRule should probably look more like RewriteRule ^some-template(.*)$ ./some-template.php$1. That way the $1 has something to refer back to.
    – Pat J
    Jan 27, 2014 at 19:36
  • Interesting idea, I might try it. I could get over the page creation problem by restricting users from creating a page with that specific name. Jan 27, 2014 at 21:32
  • 1
    @patj you are right, but actually it would be better not to add the $1 in the first place ;-) my mistake.
    – fischi
    Jan 27, 2014 at 22:34
  • Yeah, I kind of waffled on which one you meant, and chose wrong.
    – Pat J
    Jan 28, 2014 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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