GeneratePress: How to Set Sidebar Width with PHP

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.

JM

Sobre Jose manuel

I am José Manuel. I started a WordPress blog in 2011 as a hobby to use it a part of my teaching and I fell in love with blogging & WordPress.

I am writing about things I know and things that I am learning. I hope you find some of the things I write useful.