• So I have a ‘front-page.php’ template.
    I also have a ‘no-sidebar.php’ template.

    If someone set’s their ‘front-page’ to a page using the ‘no-sidebar’ template, I don’t want the sidebar to show.

    If they set their ‘front-page’ to a page using the ‘default sidebar’ template, I need the sidebar to show.

    In the front page template, I need this kind of php (I think) but I don’t know how to write it:
    if page template selected disable sidebar else show sidebar

Viewing 5 replies - 1 through 5 (of 5 total)
  • You could use the is_page_template() function to check whether you’re using a particular or not. You can read about how it works in the Developer Reference. An example of this would be:

    if ( true === is_page_template( 'xyz.php' ); ) {
    
        get_sidebar();
    
    }

    Although if your templates are selectable from the edit page screen in the Page Attributes section (where you edit the page content), then simply having two separate templates, one with a sidebar and one without would be fine. No need for an if statement like above.

    Thread Starter pixelboutiqueuk

    (@pixelboutiqueuk)

    I already have a page template for the no-sidebar that is selected under the page attributes, but when I set that page as my static front page, it pulls in my ‘front-page.php’ template and shows the sidebar.

    I need to disable the sidebar on the front-page.php for the no-sidebar.php template ONLY and leave the sidebar in place for default templates.

    Hello,
    You just check is it a home page and front page or not.
    Use below code to create your condition where you need.

    
    <?php if(is_home() && is_front_page()): ?>
    <?php endif; ?>
    

    Thanks.

    Thread Starter pixelboutiqueuk

    (@pixelboutiqueuk)

    I managed to work that bit out ?? Thanks.

    The front-page with the no-sidebar template applied now has no sidebar, however it is not pulling in the full width aspect of the no-sidebar page template now ??

    Thread Starter pixelboutiqueuk

    (@pixelboutiqueuk)

    I fixed it by adding this to my front-page.php:

    	<?php if (is_page_template('front-page.php' && 'no-sidebar.php') ) : ?>
    		<div id="primary" class="content-area-no-sidebar">
    			<main id="main" class="site-main">
    	<?php else : ?>
    		<div id="primary" class="content-area">
    			<main id="main" class="site-main">
    	<?php endif; ?>

    I don’t know how best practice this is but it works!

    Thanks everyone.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove sidebar on front-page’ is closed to new replies.