• Good Afternoon!

    I need help disabling a sidebar on a specific page.
    My theme does not have an option to do this.

    I have created a custom field titled: disableSidebar and
    I have set the value to true

    can someone please provide me the bit of php to have this specific page sidebar free???

    Thank you!

    Love,

    Jake

    https://www.whatwelivefor.com

Viewing 15 replies - 1 through 15 (of 28 total)
  • It’s actually super simple, but to help you I may need some info.

    • What are you using to create the custom field?
    • Which page template are you trying to edit?

    Usually you would just fetch the value of the field and write something along the lines if true do nothing, if false echo sidebar.

    Obviously you’d put the get_sidebar call inside of that if statement in your page template.

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    I pasted this bit of code in my page.php

    ‘<?php // look to see if we’ve disabled sidebar in a custom field, if not show it
    $disableSidebar = get_post_meta($post->ID, ‘disableSidebar’, $single = true);
    if ($disableSidebar !== ‘true’) { get_sidebar(); }
    ?>’

    I’m trying to edit a hidden page that you can find by typing in WWLF family in the search bar.

    I just need this one page without the side bar, but I believe this code was supposed to allow me to create custom fields for any page and disable sidebars by setting the value to true.

    May I please have a link to the page (assuming it’s on a server)?

    The main factors are: 1) knowing which file is being pulled.
    2) checking to see if you can have it pull a unique file.
    3) If that’s not possible, writing a couple more if statements.
    4) actually implementing the code.

    Assuming you don’t have an extra get_sidebar(); call somewhere on the page, I don’t see why that wouldn’t work (also assuming that you’re editing the proper file for that particular page).

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    https://www.whatwelivefor.com/?s=wwlf+family

    I do not believe I have an extra side bar.
    I’m pasting the code in my child theme page.php

    I mean, can I just hard code my page.php to just exclude
    a particular post ID since I just need one page side bar
    excluded?

    Oh, that’s the search.php template file.
    Edit that and you’re good ??

    Honestly if you want to hide the sidebar on the search page, simply remove the sidebar call (no need for an if function or a field).

    Open search.php , find the part that fetches the sidebar (usually get_sidebar();) and just remove it.

    Keep in mind that you might want to do some html and css adjustements if you’re removing the sidebar, to actually fill the full width of the page with the search results.

    Where it says.
    <div id="primary" class="conten-area">
    or something along those lines, just add another class to the div “search_results_fix”. Then in your style.css write something along the lines of:
    #primary.search_results_fix {width:100% !important;}

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    hmmm…

    I just pasted

    <?php // look to see if we've disabled sidebar in a custom field, if not show it
    $disableSidebar = get_post_meta($post->ID, 'disableSidebar', $single = true);
    if ($disableSidebar !== 'true') { get_sidebar(); }
    ?>

    into the search.php to replace it with

    php get_sidebar

    and it didn’t work?

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    AHHHH!!!!

    I didn’t create a child search.php!!!

    YOU’RE THE BEST!!!!!!!!!!!!!!

    Thank you for your help!!!!!!!!!!

    I’m so sorry I didn’t do a good job of explaining my problem but you helped me soooo much!!!!!!!!!!!!

    Yay!!!!!!!!!!

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    well… it was working, now it’s not.

    :/

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    It works but the side bar appears after I refresh the page.

    Is this a cache thing?

    It could be, or you might have just overwritten it. Honestly I know nothing about child themes, so I can’t really help that much in that regard. What I am certain is that the file used is search.php, so I would just go ahead and remove the whole get_sidebar line in that file.

    Alternatively if you could paste the search.php file contents, that’d be a great help ??

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    <?php
    /**
     * The template for displaying Search Results pages.
     *
     * @package Kavya
     */
    
    get_header(); ?>
    
    	<section id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    		<?php if ( have_posts() ) : ?>
    
    			<header class="page-header">
    				<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'kavya' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
    			</header><!-- .page-header -->
    
    			<?php /* Start the Loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php get_template_part( 'content', 'search' ); ?>
    
    			<?php endwhile; ?>
    
    			<?php kavya_paging_nav( 'nav-below' ); ?>
    
    		<?php else : ?>
    
    			<?php get_template_part( 'content', 'none' ); ?>
    
    		<?php endif; ?>
    
    		</main><!-- #main -->
    	</section><!-- #primary -->
    
    <?php // look to see if we've disabled sidebar in a custom field, if not show it
    $disableSidebar = get_post_meta($post->ID, 'disableSidebar', $single = true);
    if ($disableSidebar !== 'true') { get_sidebar(); }
    ?>
    <?php get_footer(); ?>

    Thank you so much for helping. I’m just so confused why the sidebar would keep appearing after I refresh

    Here you go:

    <?php
    /**
     * The template for displaying Search Results pages.
     *
     * @package Kavya
     */
    
    get_header(); ?>
    
    	<section id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    		<?php if ( have_posts() ) : ?>
    
    			<header class="page-header">
    				<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'kavya' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
    			</header><!-- .page-header -->
    
    			<?php /* Start the Loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php get_template_part( 'content', 'search' ); ?>
    
    			<?php endwhile; ?>
    
    			<?php kavya_paging_nav( 'nav-below' ); ?>
    
    		<?php else : ?>
    
    			<?php get_template_part( 'content', 'none' ); ?>
    
    		<?php endif; ?>
    
    		</main><!-- #main -->
    	</section><!-- #primary -->
    <?php get_footer(); ?>

    I’ve removed the whole sidebar part as you don’t need it. This will only affect the search results page (https://www.whatwelivefor.com/?s=uz).

    Lemme know if it works ??

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    Thank you again for your help, but unfortunately the side bar is still there!

    It worked initially then when i searched the page again and other hidden pages it pops back up.

    Wouldn’t that be impossible though?

    1) are you using a caching plugin (try clearing the cache or possibly deactivating the plugin)?
    2) Do you have this version of the search.php in your child theme folder?
    3) Try just editing the parent theme search.php (I know – usually a bad idea, but then again I’ve never worked with child themes in my 8 years of being a web dev lol)

    Thread Starter JacobHenderson5989

    (@jacobhenderson5989)

    I cleared my cache and deactivated the plugin

    I have the search.php in my child theme folder and my appearance/editor is pointing to it along with my other child themes

    I edited the parent theme as well, but again, since I’m using a child theme it won’t be affected

Viewing 15 replies - 1 through 15 (of 28 total)
  • The topic ‘Disable sidebar on a specific page’ is closed to new replies.