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.

Manuel Campos, English Professor

Manuel Campos

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.

WP SURFER

home

about

privacy

contact

© 2024 WP SURFER • Made with Love in Costa Rica