0

I want my website's content (posts) to be central in the page when the sidebar is inactive. I've currently got it set to fit both the content AND the sidebar on the same page. How can I make it correct itself if the sidebar is inactive?

I am using get_sidebar();

Here's my website that I'm referring to.

  • How are you calling your sidebar? There's get_sidebar() and dynamic_sidebar() which can be used separately or together. There may be another method you're using that I'm not familiar with but either way please edit your question and add how you're calling your sidebar. – Howdy_McGee Dec 10 '14 at 18:48
  • @Howdy_McGee I am using get_sidebar() – Rockett Dec 11 '14 at 14:09
0

You could try something like this, within your sidebar.php file:

if ( ! is_active_sidebar ('SIDEBAR-NAME-OR-ID' ) ) {
    echo '<style>.main-content { width: 960px; }</style>';
}

This is hackish, but it should work for what you're trying to do. There may be a better method but its hard to know without more context. The above code just spits out an inline style rule to full-width your .main-content wrapper if no widgets are present in the sidebar. The wrapper currently is set to 620px in your stylesheet (why it's not full-width).

  • That worked and I like it! However I feel this might be bad practice? Is it really a deal breaker if I'm planning on distributing this theme for the public? – Rockett Dec 11 '14 at 16:36
  • You generally want to avoid inline styles when possible. If you need to pass theme review, try adding that to a function, and then hooking the function into wp_head. That will at least move the <style> tag to the <head> section, which should be sufficient. – edwardr Dec 11 '14 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.