{"id":1969,"date":"2021-06-05T20:33:27","date_gmt":"2021-06-05T20:33:27","guid":{"rendered":"http:\/\/localhost:10003\/?p=1969"},"modified":"2021-06-05T20:33:27","modified_gmt":"2021-06-05T20:33:27","slug":"remove-the-sidebar-in-wp-rig","status":"publish","type":"post","link":"https:\/\/thewpgeek.com\/remove-the-sidebar-in-wp-rig\/","title":{"rendered":"Remove the Sidebar on certain pages in Wp-Rig"},"content":{"rendered":"\n

Theme developers often make the design decision to remove the sidebar in certain files. I recently needed to remove the sidebar for all files that used the single.php template. Easy I thought! I dropped the file from the optional folder into the main folder : <\/p>\n\n\n\n

optional\/single.php --MOVE--> \/single.php<\/code><\/pre>\n\n\n\n

the file single.php has a get_sidebar() function that needs to be removed<\/p>\n\n\n\n

<?php\n\/**\n * The template for displaying all single posts.\n *\n * @see https:\/\/developer.wordpress.org\/themes\/basics\/template-hierarchy\/#single-post\n *\/\n\nnamespace WP_Rig\\WP_Rig;\n\nget_header();\n\nwp_rig()->print_styles('wp-rig-content');\n\n?>\n\t<main id=\"primary\" class=\"site-main\">\n\t\t<?php\n\n        while (have_posts()) {\n            the_post();\n\n            get_template_part('template-parts\/content\/entry', get_post_type());\n        }\n        ?>\n\t<\/main><!-- #primary -->\n<?php\n\/\/ get_sidebar() remove sidebar from single.php posts.\nget_footer();\n<\/code><\/pre>\n\n\n\n

But, unexpectedly this actually only gets us halfway – we have the sidebar gone, but we still have it taking up space, on closer inspection, a class is added “.has-sidebar” so let’s work at removing that. Load up .\/inc\/Sidebars\/Component.php<\/strong><\/p>\n\n\n\n

 \/**\n     * Adds custom classes to indicate whether a sidebar is present to the array of body classes.\n     *\n     * @param array $classes classes for the body element\n     *\n     * @return array filtered body classes\n     *\/\n    public function filter_body_classes(array $classes): array\n    {\n        if ($this->is_primary_sidebar_active()) {\n            global $template;\n\n            if (!in_array(basename($template), ['front-page.php', 'single.php', '404.php', '500.php', 'offline.php'])) {\n                $classes[] = 'has-sidebar';\n            }\n        }\n\n        return $classes;\n    }\n<\/code><\/pre>\n\n\n\n

find the above code, where you will see an array of pages that don’t have that sidebar class added, just add single.php as I have above. (or whatever template file you need to remove the sidebar).<\/p>\n\n\n\n

All done!<\/p>\n","protected":false},"excerpt":{"rendered":"

Theme developers often make the design decision to remove the sidebar in certain files. I recently needed to remove the sidebar for all files that used the single.php template. Easy I thought! I dropped the file from the optional folder into the main folder : the file single.php has a get_sidebar() function that needs to […]<\/p>\n","protected":false},"author":2,"featured_media":1974,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[1],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"rigtest-featured":false,"mailpoet_newsletter_max":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/thewpgeek.com\/author\/admin\/"},"uagb_comment_info":3,"uagb_excerpt":"Theme developers often make the design decision to remove the sidebar in certain files. I recently needed to remove the sidebar for all files that used the single.php template. Easy I thought! I dropped the file from the optional folder into the main folder : the file single.php has a get_sidebar() function that needs to…","_links":{"self":[{"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/posts\/1969"}],"collection":[{"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/comments?post=1969"}],"version-history":[{"count":0,"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/posts\/1969\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thewpgeek.com\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/media?parent=1969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/categories?post=1969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thewpgeek.com\/wp-json\/wp\/v2\/tags?post=1969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}