Archived topic
generate_right_sidebar_width
3 replies · Started by Randy on December 13, 2020
For filters such as generate_right_sidebar_width, can I use the GP Premium Elements module to add these Hooks? And if so, which Hook do you apply it to and do you check the "Execute PHP" box?
add_filter( 'generate_right_sidebar_width', function() {
return 0;
} );
Would the above hide the right sidebar? Can't get this to work.
Hi there,
Our Elements module shouldn't be used to execute functions like this - it's purely a presentational tool.
To add functions, you should use one of these methods: https://docs.generatepress.com/article/adding-php/
You would need to use this filter to remove a sidebar: https://docs.generatepress.com/article/generate_sidebar_layout/
More info here: https://docs.generatepress.com/article/sidebar-layout
Cool, good to know. Wish you guys also made a Code Snippets tool and/or added similar functionality to your GP Premium. Great products you have!
In case it helps anyone else looking to do this, I used the Code Snippets plugin to hide the sidebar on static pages if the url parameter &myparam=myvalue is set:
add_filter( 'generate_sidebar_layout', function( $layout ) {
$var = $_GET["myparam"];
if (
$var === "myvalue"
&&
is_page()
) {
return 'no-sidebar';
}
return $layout;
} );
Awesome, thanks for sharing the code! :)