Archived topic
Custom Right-side bar width
8 replies · Started by Dev on January 9, 2021
Hello,
On a few single posts, I want to set my right sidebar width to 25, and my global right sidebar width is 30.
How can I make the right side bar width to 25 for a few posts?
Please let me know.
Hi there,
this topic explains:
Hello,
I'm confused. Like I want to change the right sidebar width for the post id 27468, then in that case, what will be my CSS CODE.
I'm confused because I want to change the width only on a few posts and pages, not on the homepage, and the below CSS code is saying something about the homepage.
Can you please tell me the exact one I need to use?
add_filter( 'generate_right_sidebar_width','tu_custom_right_sidebar_width' );
function tu_custom_right_sidebar_width( $width ) {
// If we're on the home page
if ( is_front_page() ) {
return 40;
}
// Return the default
return $width;
}
Do you have a list of Post IDs that you want to make this change ?
Let me know and ill provide you the PHP code you require.
Hello,
Below is the post ids for now.
27026, 27468, 27225, 27104, 26930, 24603, 26853, 24763
But soon, I will add more post id's in it. So at that time, do we need to change the PHP code? And how and where to add PHP code? I had never added PHP code, so I don't know where and how to add it.
Please let me know.
Hello,
I read how to add PHP code, but all ways are looking a bit risky to me as your posts say that the site can turn into blank white as well.
Can't u give me CSS CODE rather than PHP CODE?
If not, then please suggest the safest way to add PHP CODE.
PHP is the best method for this.
Try this:
add_filter( 'generate_right_sidebar_width','tu_custom_right_sidebar_width' );
function tu_custom_right_sidebar_width( $width ) {
// If we're on the home page
if ( is_single( array( 27026, 27468, 27225, 27104, 26930, 24603, 26853, 24763 ) ) ) {
return 40;
}
// Return the default
return $width;
}
I read how to add PHP code, but all ways are looking a bit risky to me as your posts say that the site can turn into blank white as well.
Code Snippets is the easiest and safest method as it prevents that issue:
https://docs.generatepress.com/article/adding-php/#code-snippets
Thanks, it worked well. Great.
No problem :)