The Template Hierarchy has a set of filters to let you modify what template gets loaded for each type of query. In this case you can use home_template
.
You’ll have to do some work to implement your own interface for choosing a template, via the Theme Mods API/Customizer API, or there are also a number of plugins to let you create theme option pages.
In this example, we hook home_template
and check for an Option named wpd_home_template_shows_sidebar
, and load the template with-sidebar.php
if it exists. Note that we return
the $template
passed to the function in either case.
function wpd_home_template( $template ) {
if( get_option( 'wpd_home_template_shows_sidebar' ) ){
$template = locate_template( 'with-sidebar.php' );
}
return $template;
}
add_filter( 'home_template', 'wpd_home_template' );
Related Posts:
- is_home() returns TRUE on page template
- creating single page with 2 columns while theme is 3 column
- Different template parts when on different pages
- WordPress blog posts template bug [closed]
- Custom templates not showing up in template dropdown
- Get page id by template
- Change page template programmatically ?
- Listing pages which uses specific template [duplicate]
- Is there a way to change the default page template selection?
- Show Default Editor on Blog Page ( Administration Panel )
- Hide page visual editor if certain template is selected?
- Creating a template using a specific slug name, for a page with a parent page
- How to embed page content in a blog post
- Change admin startpage to Pages-page?
- Limit number of pages that use a specific template?
- Hide page visual editor if template is selected – redux
- WP is not using the select custom template.php that its selected for a page
- Page template gives ‘Parse error: syntax error’ when used, but no error found!
- more tag in the $post->content when get_pages were used
- How to change the permalink structure of a master page?
- Why is custom template not seen as page with is_page()?
- Page with page template not using template in Preview
- Can’t change parent page
- Template for child pages / subpages
- How to dynamically save a selected option from page “Templates” selectbox?
- Sitewide page on all the blogs in the network
- Redirect “Sorry, you are not allowed to access this page.” to Home
- How to display thumbnail and excerpt of a page on homepage?
- Custom /page/2/ template (different from index.php)
- Include a specific page in your template
- Is it possible to have a landing page based on the visitors location?
- Custom page template not working
- How do I create a separate page for each author?
- How do I pass data from page content to the underlying PHP template
- Making a wordpress page the index on the site?
- How to change only the home page / front page url on wordpress
- How do i change page template in bulk?
- Load specific page template based on URI
- I have index.php and other files, how do I display other pages?
- Using Pages to handle calls for custom post types
- How to make tag post listing page working?
- Site url is not showing the home page
- How can I get the homepage from the loop?
- Custom page template with entirely different design. Is it possible in?
- How to make my category archive behave like a page
- Page template no longer exists – metaboxes won’t save
- page-name.php doesn’t execute on custom template
- Updated WordPress, now getting errors on site
- My custom template page not loading content inside it?
- Remove Content edit box from ALL pages (not posts)
- Is it possible to activate page template without manually selecting it in wp-admin?
- Hide page templates without using ‘unset’
- Add a static page that links to homepage
- the_content of template page
- How can I get the blog page ID?
- Why won’t pagination work?
- Can I change the “Home” text in the menu?
- Parent page shows no child content
- Use same page-mypage.php template for several pages
- pre-existing data, and entities
- Rewrite to load homepage for a different url
- Avoid pages losing template association on site re-deploy
- Need to create a custom page on a website
- Later blog post pages give 404 error
- List child pages within page template
- Using page-something.php as static front page
- Best way to organize data in this scenario
- Displaying posts on homepage – Template Page
- Setting a homepage – doesn’t seem to work
- Using index.php as page template
- Page Title repeating
- How do i create a list-posts-page?
- How does wordpress link page templates to individual pages
- Is there a template tag/function for getting the URL (or slug or name or ID) of the blog page when using a “static” front page
- Displaying the blog entries in a Page (using get_posts to retrieve the posts)?
- Limit the amount of main pages
- Embedding Password Protected (Private) “Blog Posts” BLOCK that shows Images and Excerpts on Password Protected Page (not the home page)
- Create custom page to author.php
- On the list of Pages, clicking to Edit a particular page redirects to the list of trash
- Template field missing in page attributes
- Updating page template pragmatically
- URL redirect to home page issue in word press site
- How to change default home link title?
- Static Home Page resets to Front Page
- Why my home page doesnt work?
- Adding styles/scripts to specific page
- How to publish pages under a subdomain url?
- How to detect if some page template has been selected
- WordPress form submit to custom page template does not work
- Display grandchild page content on parent page
- How do you assign custom template for Posts page (under Front page displays setting)
- display different pages content on single page
- How to output different content of page on different places in my template
- Avada Theme – Display results from a specific category [closed]
- Multiple pages to show posts
- How to finish this loop?
- Auto-Create Pages from Template Directory
- Loading custom jQuery and HTML in a WordPress page
- different single.php for different page templates
- how bbPress and buddypress add their own page templates to the page template drop down on the page editing screen