Move WooCommerce Cart Toggle Into the Menu Items

Move WooCommerce Cart Toggle Into the Menu Items

By default, the WooCommerce cart icon is separated from the main menu like this:

If you prefer move the icon as part of the menu items like this:

Then try the following PHP snippet:

add_filter( 'wp_nav_menu_items', function( $items, $args ) {
if ( 'primary' === $args->theme_location ) {
$has_items = false;

if ( ! WC()->cart->is_empty() ) {
$has_items = 'has-items';
}

return sprintf(
'%1$s

',
$items,
generatepress_wc_cart_link(),
is_cart() ? 'current-menu-item' : '',
$has_items
);
}

return $items;
}, 10, 2 );

generate_header_element_display

generate_header_element_display

The generate_header_element_display allows us to bypass the Display Rules, so we can enable or disable an Element under our own conditions.

Examples

For example, if we want to assign a specific header to Author Tom only:

add_filter( 'generate_header_element_display', function( $display, $element_id ) {
if ( 10 === $element_id && is_author( 'Tom' ) ) {
$display = true;
}

return $display;
}, 10, 2 );

Another request that we get from time to time is to only show page hero on first archive or posts page and turn off for 2nd and subsequent pages of posts. This can be done with the snippet below:

add_filter( 'generate_header_element_display', function( $display ) {
if ( is_paged() ) {
$display = false;
}

return $display;
} );

Or we can disable the header element if no featured image is added:

add_filter( 'generate_header_element_display', function( $display, $element_id ) {
if ( 123 === $element_id ) { // Only target specific Element
if ( ! has_post_thumbnail() ) {
$display = false;
}
}

return $display;
}, 10, 2 );

Similarly, we can disable the header element if no featured image is added or if featured image is disabled using the disable element metabox:

add_filter( 'generate_header_element_display', function( $display, $element_id ) {
if ( 123 === $element_id ) { // Only target specific Element
if ( !has_post_thumbnail($post->ID) || get_post_meta( get_the_ID(), '_generate-disable-post-image', true ) === 'true' ) {
$display = false;
}
}
return $display;
}, 10, 2 );

Layout Element Overview

Layout Element Overview

Starting in GP Premium 1.7, the Layout element allows you to set the same options you』re used to in the Layout metabox, but on a site-wide scale.

This means you can change the sidebar layout on specific categories for example, or set the content layout to full width on your entire site if you』re using a page builder everywhere.

This element is a massive time saver.

Layout Metabox Overview

Layout Metabox Overview

Please note that WordPress ignores metabox values on index pages like blog and archive so this meta box won』t work for those pages.

Sidebar Layout

Footer Widgets

Disable Elements Overview

Content Container

Where Is It?

The Layout is usually located at the bottom right corner of the block editor screen:

If you don』t see the metabox there, make sure to enable it under Options setting:

Disable Elements Overview

Disable Elements Overview

The Disable Elements add-on in GP Premium allows you to disable certain elements on your individual pages and posts.

Starting in GP Premium 1.7, you can also use the Layout Element to disable these elements site-wide.

To use this add-on, first make sure GP Premium is installed, and that the add-on is activated.

Once activated, you』ll find the options in the Layout metabox.

To disable the various elements, simply check the box next to their name.

Video Overview

Sidebar Layout

Sidebar Layout

There are two sidebars by default in GeneratePress that come with multiple layouts including:

Content / SidebarSidebar / ContentContent (no sidebars)Sidebar / Content / SidebarSidebar / Sidebar / ContentContent / Sidebar / Sidebar

There are three different options you can find in Customize > Layout > Sidebars. These options apply to the entire site.

Sidebar Layout

This setting refers to your regular pages.

Blog Sidebar Layout

This setting is specific for your blog, archives, search results etc..

Single Post Sidebar Layout

This setting is specific to your single posts, including blog posts or any kind of custom post type post.

Different sidebar layouts for individual pages and posts

Some individual pages and posts might require a different layout than your global settings. In this case, you can use the Layout metabox while editing that page/post.

Default Widgets

The search and archives widgets are added by default to fill the space when a sidebar layout is selected but no widgets are added in the sidebar widgets area. The two default widgets are removed automatically when you add the desired widgets in the sidebar widgets area.

If you want to remove the entire sidebar instead, then select Content (no sidebars) as explained above.

If you want to remove the default widgets but also keep the sidebar area, you can use the generate_show_default_sidebar_widgets filter.

Using a function

Note: Starting in GP Premium 1.7, the options below can be achieved using the Layout Element without writing any code at all.

Sometimes, the global settings and individual meta box won』t be enough, and you』ll have tougher conditionals to meet like specific archive pages, categories or custom post types.

In these cases, you can use the filter to set your sidebar layouts.

WooCommerce

add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are on a woocommerce page, set the sidebar
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
return 'both-left';
}

// Or else, set the regular layout
return $layout;
} );

Categories

add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are on a category, set the sidebar
if ( is_category() ) {
return 'no-sidebar';
}

// Or else, set the regular layout
return $layout;
} );

Search Results

add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are viewing search results, set the sidebar
if ( is_search() ) {
return 'no-sidebar';
}

// Or else, set the regular layout
return $layout;
} );

You can use any of the available  WordPress conditionals to determine your sidebar layout.

These are the available IDs you can return:

left-sidebar
right-sidebar
no-sidebar
both-sidebars
both-left
both-right

Learn how to add PHP here.

Content Padding

Content Padding

Note: This option requires the Spacing add-on in GP Premium.

You can adjust the padding inside your content container in Appearance > Customize > Layout > Container.

The value you see is in pixels, and controls the amount of space between the edge of your content container and content inside of it.

Note that this can be adjusted separately for desktop and mobile by using the toggle buttons.

Content Padding Not Working

If you have content paddings set in the customizer but it』s not working/showing no paddings at all, the reason is likely that the Content Container options are being applied through the Layout Metabox or a Layout Element.

Content Container

Content Container

Starting in GeneratePress 3.0, the previous Page Builder Container option has been renamed to Content Container option.

Default

The default option means that the Content Padding option in the customizer would apply:

Full Width

The Full Width option set the content area to be 100% of the screen width and allows for full width sections using GenerateBlocks or page builders.

This option also remove the default content padding set in the customizer so GenerateBlocks or page builders can have complete control of the content padding.

Contained

The Contained option simply removes the content padding set in the customizer so GenerateBlocks or page builders can have complete control of the content padding.

Apply the Option to Multiple Pages or Globally

The Layout metabox shown in the first screenshot here allows you to choose the setting per page. You can also create a Layout Element to apply the setting to multiple pages/posts or globally.

Combine CSS

Combine CSS

By default, GeneratePress will now combine unsemantic-grid.css, style.css and mobile.css into one file. This results in fewer HTTP requests.

Existing sites will turn this option off by default to prevent any potential conflicts.

When combined, GeneratePress will use a slimmed down version of unsemantic-grid.css, which only includes the classes that are needed by the theme to function.

This option is unavailable for Flexbox version of the theme.