WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How to hide/remove sidebar on certain posts (not pages)?

[Resolved] How to hide/remove sidebar on certain posts (not pages)?

  • I tried adding this code in header.php before </head> but nothing happened:

    <?php // if page has custom field called disableSidebar = true, remove sidebar
    $disableSidebar = get_post_meta($post->ID, ‘disableSidebar’, $single = true);
    if ($disableSidebar !== ‘true’) { get_sidebar(); }
    ?>
    <?php if ( !( is_page(array('10, 16') ) ) ) { ?>
    <?php get_sidebar(); ?>
    <?php } ?>

    http://showfreetv.com

Viewing 2 replies - 1 through 2 (of 2 total)
  • Please check whether $disableSidebar has a correct data or not.

    <?php // if page has custom field called disableSidebar = true, remove sidebar
    $disableSidebar = get_post_meta($post->ID, ‘disableSidebar’, $single = true);
    var_dump($disableSidebar); // added here
    if ($disableSidebar !== ‘true’) { get_sidebar(); }
    ?>
    <?php if ( !( is_page(array('10, 16') ) ) ) { ?>
    <?php get_sidebar(); ?>
    <?php } ?>

    This code does not solve the problem, but may provide a hint to solve it.

    You’re called that outside of the loop so you need to run wp_query first. Try adding in:

    <?php  global $wp_query; ?>
    <?php $thePostID = $wp_query->post->ID; ?>
    <?php $disableSidebar = get_post_meta($thePostID, ‘disableSidebar’, $single = true); ?>
    etc...

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] How to hide/remove sidebar on certain posts (not pages)?’ is closed to new replies.
Skip to toolbar