wp_get_loading_attr_default


wp_get_loading_attr_default ( $context )

Parameters:
  • (string) context Context for the element for which the `loading` attribute value is requested.
Returns:
  • (string|bool) The default `loading` attribute value. Either 'lazy', 'eager', or a boolean `false`, to indicate that the `loading` attribute should be skipped.
Defined at:

Description

Gets the default value to use for a `loading` attribute on an element.This function should only be called for a tag and context if lazy-loading is generally enabled. The function usually returns 'lazy', but uses certain heuristics to guess whether the current element is likely to appear above the fold, in which case it returns a boolean `false`, which will lead to the `loading` attribute being omitted on the element. The purpose of this refinement is to avoid lazy-loading elements that are within the initial viewport, which can have a negative performance impact. Under the hood, the function uses {@see} every time it is called for an element within the main content. If the element is the very first content element, the `loading` attribute will be omitted. This default threshold of 1 content element to omit the `loading` attribute for can be customized using the {@see 'wp_omit_loading_attr_threshold'} filter.

Related Functions

wp_get_widget_defaults, get_metadata_default, wp_img_tag_add_loading_attr, wp_omit_loading_attr_threshold, _get_admin_bar_pref

Top Google Results

User discussions

wpseek mobile