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 45 you can create a template with the file name page-45.php. See template hierarchy.
  • Use a reusable page template. See page templates in Codex.
  • Use the filter template_include filter to use any template file you may want, from any location, for you page. See template_include documentation.

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.

Tags: Pages / Themes

Similar questions

Wp Custom menu problem: the link is opened in the new tab and meanwhile the same tab
I have problem with one wp custom menu, from Apperance > Menus i set that link to open in new tab. When i go to the web site, and click on Forum (which is button who i want to open in new tab), new tab with the forum is opened but, meanwhile in the main tab where it's supposed to be the WordPress i have the forum loaded and i must go back via butto...
Need to open link in new tab and close current tab with one click
I find myself in need of a script to (1) open a link in a new tab and (2) close the current tab so the back button cannot be used to see the website that was previously being viewed. This is a security feature for a site, and unfortunately I'm at a complete loss. Nothing I've tried works and I don't know where to begin. This is likely very simple a...
how can I change the height of a jquery flexslider belongs to jquery.flexslider-min.js file?
My wordpress theme contains a jquery flexslider (version:jquery.flexslider-min.js) and the problem is that when I've tried to change the height of it by modifying the height parameter of the slider (by setting fix and auto) in .css and uploading narrower pictures it appeared that the slider was displayed in the intended shape but the navigation arr...
How to add a menu that belongs to parent blog to all child-blogs?
I want to add a menu that belongs to parent multisite blog to all child-blogs. I need the menu displayed in all child-blogs, I mean the same menu on all multisites blogs. How I can do that?
Add custom field to product settings shipping tab and display value on additional information tab in WooCommerce
I'm trying to add a "Quantity per package" field to WooCommerce product, and I'd need this field in the Shipping tab of the product backend. Then I need to display this number under the package dimensions in the Additional Informations tab. I could add a row to the Additional Informations tab, but I don't know how to input the value and m...
How to add tab "ALL" to menu tab dynamically
I have a dynamic tab list, I wanted to add a tab "All" The click of tab 3all" display all pots For this code, it only shows dynamic tab, so, I am looking for a solution to add a tab "All" I tried some solution but I did not arrive The idea it'is to add atatic tab "All"

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.