GeneratePress: How to Set Sidebar Width with PHP

Manuel campos

This is the code snippet that you need to set the right sidebar width of the homepage

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

This is the code snippet that you need to set the right sidebar width of your category pages

add_filter( 'generate_left_sidebar_width','tu_custom_left_sidebar_width' );
function tu_custom_left_sidebar_width( $width ) {
        // If we're on a category
        if ( category() ) {
                return 40;
        }
        
        // Return the default
        return $width;
}

This is the code snippet that you need to set the right sidebar width of your blog post

add_filter( 'generate_right_sidebar_width','tu_custom_right_sidebar_width' );
function tu_custom_right_sidebar_width( $width ) {
        // If Post
	if ( is_single() ) {
		return 28;
	}
	
        // Return the default
	return $width;
}

This is the code snippet that you need to set the left sidebar width of your blog post

add_filter( 'generate_left_sidebar_width','tu_custom_left_sidebar_width' );
function tu_custom_left_sidebar_width( $width ) {
        // If Post
	if ( is_single() ) {
		return 28;
	}
	
        // Return the default
	return $width;
}

Change the number in the code to whatever makes sense for you.

Wanna buy me a Coffee?
JM
About me
I am José Manuel. I am writing about things I know and things that I am learning about WordPress. I hope you find the content of this blog useful.
Linktree
Care for Site Speed?
I think you can’t go wrong with Cloudways, CloudFlare, and Perfmatters.
Perfmatters Cloudways

WPSurfer.com

Resources to host, secure, speed up, rank, and monetize your WordPress sites.
Plugins
Services
Connect
LinkedIn
Facebook
LinkTree