0

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...

2 Answers 2

0

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.

1
  • got it, I will test it, sounds a good idea
    – sergio
    Commented May 6, 2015 at 15:19
0

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.

2
  • Thanks! I got the idea, so pages, posts comments, all that is content and saved in the database belongs to the site...As for the piece of code you mentioned, I understand this is in case I wanted a specific theme for each page, right? thanks again for your help
    – sergio
    Commented May 6, 2015 at 14:30
  • Yes, the posted code is in case you want a specific theme for each page.
    – cybmeta
    Commented May 6, 2015 at 22:04

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.