• Resolved ken78

    (@ken78)


    I’m currently trying to figure out why an image below the fold on my website is having fetchpriority=high applied to it. I have all other plugins that optimize content on my site disabled and even made sure WP Core itself is not applying the attribute either. On further inspection of the image, I noticed it is actually within the query loop container for Generate Blocks I have implemented on my website as a custom solution to sort some posts by a date meta-field. This leads me to suspect that Generate Blocks is auto-applying the fetchpriority=high attribute to the first post within its query loop.

    If this is correct, could someone kindly give me a .php code snippet I could inject into my site footers on the affected pages to prevent Generate Blocks from applying fetchpriority attributes to any images called by its query loop as I want all image attributes to managed solely by my implementation of WP Rocket on my site.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Alvind

    (@alvindcaesar)

    Hi there,

    That was added by WordPress itself starting from version 6.3. You can refer to this article:

    Image performance enhancements in WordPress 6.3

    Thread Starter ken78

    (@ken78)

    Solved my own issue thanks to some help on the main feedback form here: https://ww.wp.xz.cn/support/topic/how-to-disable-automated-wp-core-fetchpriorityhigh-application/#post-18464473

    I was utilizing the following function hook for Generate Blocks to sort my posts by a custom meta date field:

    //DATE type custom field value
    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {

    // apply filter if loop has class: order-by-end-date
    if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order-by-end-date' ) !== false ) {

    $query_args = array_merge( $query_args, array(
    'meta_key' => 'end_date',
    'meta_type' => 'DATE',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    ));
    }
    return $query_args;
    }, 10, 2 );

    Due to the way it operates, it seems to keep the fetchpriority=high attribute that was applied by WP Core even after having another function run at priority level 99 to remove this attribute.

    The following is my final code that removes the fetchpriority being added by WP Core, while still preserving the functionality of the meta date post order:

    //DATE type custom field value
    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {

    // apply filter if loop has class: order-by-end-date
    if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order-by-end-date' ) !== false ) {

    $query_args = array_merge( $query_args, array(
    'meta_key' => 'end_date',
    'meta_type' => 'DATE',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    ));
    }
    return $query_args;
    }, 10, 2 );

    add_filter( 'wp_get_loading_optimization_attributes', function( $attributes, $context ) {
    if ( isset( $attributes['fetchpriority'] ) && $attributes['fetchpriority'] === 'high' ) {
    unset( $attributes['fetchpriority'] );
    }
    return $attributes;
    }, 11, 2 );

    Hopefully this helps someone else out that is scratching their head on why they cannot get WP Core fetchpriority=high attributes removed from images pulled by Generateblocks queries.

    If you are ordering your queries, place the unset function call at the end of your ordering functioning and set the priority to 11 (or 1 lower than whatever your priority is for your order function). This will fix the issue.

    Thank you.

    • This reply was modified 1 year ago by ken78.
    Plugin Support Alvind

    (@alvindcaesar)

    Thank you for sharing your solution!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Does Generateblocks automatically add fetchpriority=high attributes?’ is closed to new replies.