I need to create a plugin that makes custom page templates available in wp-admin. I’m wondering if someone has tackled this already, as it seems like a pretty typical process?
Leave a Reply
You must be logged in to post a comment.
I need to create a plugin that makes custom page templates available in wp-admin. I’m wondering if someone has tackled this already, as it seems like a pretty typical process?
You must be logged in to post a comment.
Like Rarst answered you can really do that without editing core files or remove the page attributes metabox and create your on using the same code with a bit of modification.
the code below is the code for the /admin/include/meta-boxes.php
and i added the a comment to show where your extra page template options would go:
Don’t know if this is a fix in your case but i had a smiler case when i needed to display the post type in a plugin built-in theme and for that i used
add_filter('the_content', 'my-function');
and my-function created the output to display.
Another option would be to make your plugin create the template file in the current theme directory , something like this:
and you can run this after you first check if the file exist
Hope one of this helps.
I’m not entirely sure I understand what you are trying to achieve, at least why you would want a plugin to do that.
The normal procedure for creating different page templates is:
Create a new page-template in your ACTIVE theme directory (make a copy of page.php).
Change the name of the template (inside the file).
/*
Template Name: Full Width Page
*/
Change the code of the page to what you are trying to achieve.
You can now go create a new page and choose which “Template” to use.
…
I hope that is what you are trying to achieve?
Official documentation here: http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates
This seems to be quite hard to achieve.
get_page_templates()
function actively discards anything that is not located in parent and child root directories. It also doesn’t store in global variable or allow to filter generated list of templates.I think page attributes meta box will need to be forked and completely replaced for this. And not sure it will be possible even then.
I agree that this seems like something that makes sense, but WordPress code is very precise in that it wants named templates to only come from theme’s directory.
Isn’t doing this one of the reasons that
register_theme_directory()
got introduced?http://core.trac.wordpress.org/ticket/10467
At the time it was an issue related to BuddyPress, which wanted to toss in extra templates here and there.
I take it they’re not properly listed as page templates, though:
http://core.trac.wordpress.org/ticket/15803