Design System is here - Read the release post

Learn GeneratePress

Developers

Overlays, menus and accordion (Pro)

Hooks for Overlay Panels (pop-ups, modals and mega menus), the Classic Menu block and the accordion’s FAQ schema. They are all GenerateBlocks Pro features.

Jump to

Overlay Panels

generateblocks_overlays_capability

GB Pro — since GenerateBlocks 2.4.

The generateblocks_overlays_capability filter sets the capability needed to use or manage Overlay Panels.

Parameters: $capability (string, the capability required), $context (string: use to select existing overlays, or manage to create, edit and open the dashboard). Default: edit_posts for use, manage_options for manage.

Example: allow Editors to create and edit Overlay Panels.

add_filter('generateblocks_overlays_capability', function ($capability, $context) {
    if ('manage' === $context) {
        return 'edit_others_posts';
    }
    return $capability;
}, 10, 2);

Related: generateblocks_conditions_capability Guide: Overlay Panels

generateblocks_overlay_post_id

GB Pro

The generateblocks_overlay_post_id filter changes the ID of each active Overlay Panel before it is added to the page. Use it to swap an overlay for another, for example a translation.

Parameters: $post_id (int, the overlay’s post ID). Default: the ID of each published overlay that is turned on.

add_filter( 'generateblocks_overlay_post_id', function( $post_id ) {
    // Use the translated overlay when your multilingual plugin has one.
    return apply_filters( 'wpml_object_id', $post_id, 'gblocks_overlay', true );
} );

Related: generateblocks_overlay_panel Guide: Overlay Panels

generateblocks_overlay_panel

GB Pro

The generateblocks_overlay_panel filter changes the rendered HTML of an Overlay Panel’s content. Only published overlays without a password are rendered.

Parameters: $content (string, the rendered blocks), $post_id (int|null, the overlay’s post ID). Default: the overlay’s blocks rendered with do_blocks(), after embeds are processed.

add_filter( 'generateblocks_overlay_panel', function( $content, $post_id ) {
    return $content . '<p class="my-overlay-note">' . esc_html__( 'Thanks for visiting.', 'my-plugin' ) . '</p>';
}, 10, 2 );

Related: generateblocks_overlay_post_id Guide: Overlay Panels

generateblocks_pro_overlay_allow_lazy_load

GB Pro

The generateblocks_pro_overlay_allow_lazy_load filter lets an anchored or mega menu Overlay Panel keep lazy loading on its images. By default GenerateBlocks sets loading="eager" on the images of those overlays, so they are ready when the overlay opens.

Parameters: $allow (bool), $post_id (int, the overlay’s post ID), $meta (array, the overlay’s settings). Default: false.

add_filter( 'generateblocks_pro_overlay_allow_lazy_load', function( $allow, $post_id, $meta ) {
    return 123 === $post_id ? true : $allow; // Replace 123 with your overlay's ID.
}, 10, 3 );

Related: generateblocks_overlay_panel Guide: Mega Menu Overlay Panel

Back to top

Classic Menu

generateblocks_pro_after_menu_block

GB Pro

The generateblocks_pro_after_menu_block action fires after the Classic Menu block has printed its menu. Anything you echo is added to the block’s output, after the menu’s markup.

Parameters: $attributes (array, the block’s attributes), $is_admin (bool, true when the block renders in the editor). Default: none. It is an action.

add_action( 'generateblocks_pro_after_menu_block', function( $attributes, $is_admin ) {
    if ( $is_admin ) {
        return;
    }

    echo '<a class="my-menu-cta" href="/contact/">' . esc_html__( 'Contact us', 'my-plugin' ) . '</a>';
}, 10, 2 );

Related: generateblocks_overlay_panel Guide: Mega Menu Overlay Panel

Back to top

Accordion

generateblocks_faq_schema_data

GB Pro — since GenerateBlocks Pro 1.6.

The generateblocks_faq_schema_data filter changes the questions and answers GenerateBlocks prints as FAQ structured data in the page footer. The accordion adds its toggles and content to this list when its FAQ schema option is on. Duplicate questions and answers are removed, and nothing is printed when the list is empty.

Parameters: $data (array of items, each with question, answer and optionally image). Default: the questions and answers collected from the accordions on the page.

add_filter( 'generateblocks_faq_schema_data', function( $data ) {
    $data[] = [
        'question' => 'Do you offer refunds?',
        'answer'   => 'Yes, within 30 days.',
    ];

    return $data;
} );

Related: generateblocks_pro_after_menu_block Guide: GenerateBlocks Pro

Back to top