Show sidebar on blog index and posts with global layout of full-width

Hi,

I know this is a common request/enquiry on this forum and I do believe I’ve been through most if not all of the strings on the topic without finding a solution.

I have a custom post type (on which I don’t want to show a sidebar, provided through a customised plugin). However, because this post type uses the global default layout without any way of overriding this, I have to set the global default to full-width. However, this means I cannot show the sidebar on the blog index and posts. Is there a solution to this? I’m hoping there’s a way (through functions.php or perhaps the post templates) to override the layout on just the post pages?

I’m set up with an up-to-date WP, X Theme etc. I am using a child theme.

Any help much, much appreciated.

Hello There,

Thanks for writing in! To resolve your issue and make sure that the blog index will have a sidebar, please add the following code in your child theme’s functions.php file

// Make sure that  the blog index has the sidebar
// =============================================================================
function sidebars_in_blog_index($contents) {
  if ( is_home() ) {
    $contents = 'sidebar-content';
  }
  return $contents;
}
add_filter('x_option_x_layout_content', 'sidebars_in_blog_index', 5);
// =============================================================================

You can have sidebar-content if you want to display the sidebar on the left side or use content-sidebar if you want to have the sidebar to the right side.

We would loved to know if this has work for you. Thank you.

Hi @RueNel, thanks! This is great for the blog index.

However, how do I also add the sidebar to the blog posts?

Hey,

You can enable the sidebar on blog posts adding the page template here: X > Options > Blog > Template

Hi @john @RueNel, thanks but there is no options menu under X.

I imagine it is possible to force ‘posts’ to use sidebar with code similar to above; any ideas? I need this resolved by Sunday evening!

Hi There,

Please update the previous code to this:

// Make sure that  the blog index has the sidebar
// =============================================================================
function sidebars_in_blog_index($contents) {
  if ( is_home() || is_singular( 'post' ) ) {
    $contents = 'sidebar-content';
  }
  return $contents;
}
add_filter('x_option_x_layout_content', 'sidebars_in_blog_index', 5);
// =============================================================================
1 Like

@RueNel

Absolutely spot on. Thanks so much!

You’re welcome.

I’m in need of the same thing but on a PRO install with child theme. Does the same code apply; just change “x” to “pro” or is the code a bit different?

Hi @kevinwenning,

Thanks for writing to us.

The previous code works for you. Because we use the same hooks for both themes. I tested the code on my local installation with Pro theme and the code works properly.

Thanks

I’m not having any luck using that code to show the sidebar on my blog index. The posts are pushed over like there is a sidebar there, but the sidebar won’t display. I’ve played with the content width to see if it’s hiding the sidebar and changing the content width has no effect. Any ideas?

Hi @kevinwenning,

We need to examine your page, please give us the following information in a Secure Note.

  • WordPress Login URL
  • Admin level username and password
  • URL of the page you are working on

You can find the Secure Note button at the bottom of your posts.

Thank you.

Hey @kevinwenning ,

I just noticed that you’ve posted your site credentials in a secure note of someone else’s thread. Please note that secure notes are visible to staff member and original poster as well. As a security measure I’ve removed your credentials from this thread.

Please change your credentials immediately and then create a new thread with new credentials in a secure note.

Thanks!