Site logo

[Resolved] Custom Right-side bar width

Home Forums Support [Resolved] Custom Right-side bar width

Home Forums Support Custom Right-side bar width

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1612233
    Dev

    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.

    #1612317
    David
    Staff
    Customer Support
    #1612371
    Dev

    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;
    }

    #1612382
    David
    Staff
    Customer Support

    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.

    #1612394
    Dev

    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.

    #1612397
    Dev

    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.

    #1612476
    Leo
    Staff
    Customer Support

    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

    #1612735
    Dev

    Thanks, it worked well. Great.

    #1613372
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.