Ethos - Disabling SideBar on posts

How can I disable sidebars on Posts only.

Regards

Hey Paulo,

Currently, there is no option for this so layout overriding by adding custom code to the child theme’s functions.php is necessary.

Before I provide the custom code, please remember that in the future, custom coding would be unnecessary for this as there would be a Layout Builder that will allow you to build a template for single posts so you can create a template without a sidebar without coding.

For now, if you haven’t done so yet, install and activate the Pro child theme first. Next, open the child theme’s functions.php using the WordPress Theme Editor or by opening the file using cPanel or FTP Manager. If you’re not familiar with any of those, it’s recommended that you hire a WordPress developer.

If you’ll be using the Theme Editor, the setup should look like the following screenshot. The custom code added below the Additional Functions comment.

Below is the code that should be added to the child theme’s functions.php. I’ve just tested that in my site and it works.


/* Disable Sidebar for Single Posts */

add_filter('x_option_x_layout_content', 'override_layout_content_for_single');

function override_layout_content_for_single( $layout ) {  
    if ( is_singular('post') ) {
       $layout = "fullwidth";
   }
  return $layout;
}

If you read the code, you’ll notice that the layout is fullwidth for single posts.

Hope that helps.

Thanks a lot. It worked.

You’re welcome. Glad we’re able to help.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.