How to set the width of the sidebar in GeneratePress WordPress theme

GeneratePress, a lightweight WordPress theme, is highly customizable. It's possible to set the width of the sidebar in GeneratePress. You can also set the sidebar width in a fixed size (e.g. 350px.)

How to set the width of the sidebar in GeneratePress

If you are using a free version of Generate and you want to specify the sidebar width to 25%, you can use the following code snippet:

// How to set the width of Content and Sidebar areas in free version of GeneratePress
add_filter( 'generate_right_sidebar_width','lh_right_sidebar_width' );
function lh_right_sidebar_width() {
        return '25';
}

Add this code to the function file (functions.php) of the theme. Of course, I suggest you to use a child theme.

If you own a premium version, you can easily set the width of the sidebar in Customize > Layout > Sidebars under the WordPress Admin:

How to set the width of the sidebar in GeneratePress

If you want to set the sidebar width to 340px, you can use the following CSS code snippet:

/* Set the width of the right sidebar in GeneratePress to 340px */
@media (min-width: 769px) {
    #right-sidebar {
        width: 340px;
    }
    #primary {
        width: calc(100% - 340px);
    }
   }

You can change the width as you wish. In this WordPress blog, the width is set to 340px.

How to make the sidebar sticky in GeneratePress

If you want a sticky sidebar, you can just use the following CSS code:

// Make the GeneratePress sidebar sticky
@media (min-width: 769px) {
    #right-sidebar {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
    }
}

Conclusion

You can easily customize even with a free version of GeneratePress. GeneratePress is a lightweight WordPress theme available for free which is responsive and easy to use. This theme is used on this blog. It's a good option for blogs and also for other purposes.

See Also...