0

I would like to not have the sidebar when rendering individual posts and pages. Having the side bar is fine on category views, start page, etc...

I am not developing a theme, I am using an existing theme... thus what I want to avoid is hacking or child-override the template itself:

The best I was able to come up with is this in my own miniature one-file-functions.php-plugin:

add_action('wp_head', function(){       
    if ( !is_single() ) return; // only regarding posts

    unregister_sidebar('sidebar-1');
    echo '<style>
        .content-area {
            margin-right: inherit;
            width: 100%;
        }
        </style>';
});

( Of course, 'sidebar-1' and the counter-styling is template-specific - to twenty-sixteen in this case.)

Less intrusive than tampering with sidebar.php but still not that elegant... :-/

  • Isn't there a better way, to define this by normal user means on the post edit page (´/wp-admin/post-new.php´) to declare a post sidebar-less? (Ideally as the default post-type for new posts)

  • And/or even in the theme configuration? (please tell me, I am missing something obvious... )

5
  • Creating a child theme and removing get_sidebar from single.php really would probably be the easiest way. I wouldn't consider a simple child theme as hackish at all. Obviously you'd have to make sure removing get_sidebar didn't remove any divs or other layout critical to the page structure. Many themes include full width page templates that do this so you wouldn't have to create a child theme in the first place. As I think about it, maybe that's your best bet. Just create a full width page template with no sidebar yourself.
    – jetyet47
    Commented Dec 31, 2016 at 17:14
  • Do you need the whole sidebar to disappear with all the widgets?
    – prosti
    Commented Dec 31, 2016 at 18:01
  • @prosti: Yes, the entire space should be gone (in favor of the main column. Sadly many themes hide the side column but do not expand the main one.)
    – Frank N
    Commented Jan 1, 2017 at 7:55
  • You may share the single.php thought.
    – prosti
    Commented Jan 1, 2017 at 9:06
  • As a bit of a sidenote, in WP 4.7, we now have the ability to add support for custom templates in post. You could always create a custom template, and then for any post that doesn't need the sidebar, you could choose this template in a drop down menu in the WP editor. make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7 Commented Jan 1, 2017 at 15:54

1 Answer 1

1

Yes, the entire space should be gone (in favor of the main column. Sadly many themes hide the side column but do not expand the main one.

From what you said in here you would like the sidebar to disappear and at the same time the main column to expand.

This is a perfectly legal request. To do so the only the reasonable solution would be to edit the single.php file that is the template for your posts.

The HTML of your single.php file is something we should not style from functions.php.

Much easier you would typically need to remove the <?php get_sidebar(); ?> part and the update the HTML classes to expand the main column.

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.