Fetchpriority high in Overlay

  • Hi,

    I’m using overlay for megamenu with an image inside. This image get fetchpriority hight and loading eager options which I don’t prefer. But can’t disable these options.

    I’m using Perfmatters and Brian overlooked the situation. We have added a snippet now to fix the problem but it’s not the best solution we think.

    Can you help us to solve this? I want images in overlays not getting this options.

    For example you can see the contact option in: https://antilopeoutdoor.com/

    Regards,
    Kees

  • Hi Kees,

    Those attributes are added automatically by WordPress by default. Removing them would require a custom snippet, and I think your snippet is probably already the best solution.

    Can you share the snippet you’re using?

  • Hi Alvind,

    I’ve discussed with Brian from Perfmatters.io and I’ve already turned off Core fetch thrue the Perfmatters plugin. So it’s not.

    This is the snippet:

    
    /**
     * GenerateBlocks Pro Overlay Lazy Load Enabler
     * * This filter hook overrides the default behavior for GenerateBlocks Pro Overlays 
     * ('anchored' or 'mega-menu' types) to explicitly allow lazy loading.
     * * By forcing the return value to 'true', the original code snippet will skip 
     * the logic that checks if $should_allow_lazy_load is false, thereby preventing 
     * the 'loading="eager"' attribute from being forcefully added to images within the overlay.
     * * @param bool  $allow     Whether to allow lazy loading (default is false).
     * @param int   $post_id   The ID of the post where the overlay content originates.
     * @param array $meta      The overlay's block meta data.
     * @return bool Always returns true to explicitly allow lazy loading for the overlay.
     */
    function my_gb_enable_overlay_lazy_load( $allow, $post_id, $meta ) {
        // We explicitly return true to bypass the eager loading prevention logic 
        // in GenerateBlocks, allowing standard lazy loading to take effect.
        return true;
    }
    
    // Hook the function into the filter. 
    // We use a priority of 10 and ensure we accept 3 arguments to maintain compatibility 
    // with the filter's definition.
    add_filter( 'generateblocks_pro_overlay_allow_lazy_load', 'my_gb_enable_overlay_lazy_load', 10, 3 );
    
  • I reviewed the codebase to check how that filter is implemented, and it appears that GenerateBlocks adds those attributes to the Image block within the overlay.

    Your current snippet works well, but we can refine it to target only the mega menu overlay. At the moment, it removes the attributes from all overlays, which isn’t ideal.

    Here’s the modified snippet that specifically scopes the change to the mega menu overlay: :

    add_filter('generateblocks_pro_overlay_allow_lazy_load', function ($should_allow, $post_id, $meta) {
        $target_overlays = [220278]; // Your mega menu overlay ID
    
        if (in_array($post_id, $target_overlays)) {
            return true; // Allow lazy load (prevents GB from forcing eager/high)
        }
    
        return $should_allow;
    }, 10, 3);
  • Hi,

    I’ve tried to add your snippet here https://lezynestore.de/ but in the megamenu I targetted it still get’s fetchpriority high.

    This is my snippet:

    add_filter(‘generateblocks_pro_overlay_allow_lazy_load’, function ($should_allow, $post_id, $meta) {
    $target_overlays = [183581]; // Your mega menu overlay ID

    if (in_array($post_id, $target_overlays)) {
    return true; // Allow lazy load (prevents GB from forcing eager/high)
    }

    return $should_allow;
    }, 10, 3);

  • Hi there,

    I tested your original snippet and it works as expected.
    Looking at the HTML of the image in your sites mega menu I notice that the fetchpriority attribute is at the end of the markup , which doesn’t look normal , its generally before the srcset. Perhaps there is some other code or plugin that is interfering here ?

    However, we add the high priority to the images in the mega menu for a reason.
    The panel uses script to calculate its size and the position. In some cases images that are not yet loaded may affect its initial size and position; which can result in layout shifting or bad positioning.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.