How can I add a new page in the pages tab that belongs to specific theme?
Hi I would like to add new pages in my active theme but I dont want these pages appears when I move or active another theme.
I know these pages are saved in the database, but how can I link them to a specific theme?
thanks in advance for your help...
Solutions
You can customize the look and feel for a specific page within the same theme using some of these methods (maybe more):
-
Use a dedicated template for specific pages. For example, if the ID of your page is
45you can create a template with the file namepage-45.php. See template hierarchy. - Use a reusable page template. See page templates in Codex.
-
Use the filter
template_includefilter to use any template file you may want, from any location, for you page. Seetemplate_includedocumentation.
If you need help with any of these options, you can search this site about them or post a new question if don't find the answer.
There are also methods to change the active theme, I've not fully tested but this piece of code should work (in a plugin file):
add_filter( 'template', 'cyb_page_theme' );
add_filter( 'stylesheet', 'cyb_page_theme' );
add_filter( 'option_template', 'cyb_page_theme' );
add_filter( 'option_stylesheet', 'cyb_page_theme' );
function cyb_page_theme( $template = '' ) {
// Change the number with the ID/slug of the specific page
if( is_page( 20394 ) ) {
// change with the template name of the theme you want to use
$template = 'twentyfifteen';
}
return $template;
}
If you need to dinamically assign a theme to a page, you could use a meta box and a custom meta field to store the association.
Pages are an independent entity separate from whatever theme is active at that moment.
This is the design paradigm of most CMS systems that separate the concerns of site content from the view or rendering layer which allows a site owner the chance to change how his site looks without having to worry about the contents.
HOWEVER, it would theoretically be possible to build a plugin or simply hook into the template activation system within wordpress to activate or de-activate certain pages on the fly... Or the plugin could conditionally render menu's based upon the active theme slug.