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?
You may use
template_redirect
action: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 thesome-template.php
for the urlwww.mysite.com/some-template
In your
some-template.php
you load WordPress, includingwp-load.php
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.