Tuesday, September 6, 2022
HomeWordPress Developmentphp - Add attribute to featured picture with filter (wp_get_attachment_image_attributes)

php – Add attribute to featured picture with filter (wp_get_attachment_image_attributes)


I am making an attempt so as to add the fetchpriority attribute to the featured picture on my posts. I’ve seen a number of examples utilizing the wp_get_attachment_image_attributes() filter however I can not seem to get it to work.

 * Filter the featured picture output
 *
 * @package deal My_Theme
 * @since   2.3.98
 */

// Safety.
if ( ! outlined( 'ABSPATH' ) ) {
    die( 'Sorry, you aren't allowed to entry this web page straight.' );
}

/**
 * Add the fetch precedence attribute to featured pictures.
 *
 * @param array $attr The filtered attributes.
 */
perform my_theme_set_featured_priority( $attr ) {
    if ( ! array_key_exists( 'fetchpriority', $attr ) ) {
            $attr['fetchpriority'] = 'excessive';
    };
    return $attr;
}

add_filter( 'wp_get_attachment_image_attributes', 'my_theme_set_featured_priority', 10, 2 );

What is going on incorrect right here?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments