хук-фильтр since 6.1.0

wp_preload_resources

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

apply_filters( 'wp_preload_resources', array $preload_resources )

Описание

Фильтрует домены и URL-адреса для предзагрузки ресурсов.

Фильтруемое значение

Массив ресурсов и их атрибутов либо URL-адресов для вывода предзагрузки ресурсов. ...$0 array Массив атрибутов ресурса. href stringURL для включения в предзагрузку ресурсов. Обязательный. as stringКак браузер должен обрабатывать ресурс (script, style, image, document и т.д.). crossorigin stringУказывает политику CORS для заданного ресурса. type stringТип ресурса (text/html, text/css и т.д.). media stringПринимает типы носителей или медиазапросы. Позволяет адаптивную предзагрузку. imagesizes stringАдаптивный размер источника для source set. imagesrcset stringАдаптивные источники изображений для source set. fetchpriority stringЗначение fetchpriority для ресурса. Source $preload_resources = apply_filters( 'wp_preload_resources', array() ); View all references View on Trac View on GitHub Related Used byDescriptionwp_preload_resources()wp-includes/general-template.phpВыводит директивы предзагрузки ресурсов в браузеры. Changelog VersionDescription6.6.0Added the $fetchpriority attribute.6.1.0Introduced. User Contributed Notes Skip to note 2 content Robert C. 2 years ago You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Вот как можно использовать фильтр wp_preload_resources для предзагрузки стилей вашей темы. function craftedat_preload_assets( array $preload_resources ): array { /** * Check if stylesheet is loaded. * 'theme-style' is the WP handle of your stylesheet. */ if ( wp_style_is( 'theme-style' ) ) { $wp_style_theme = wp_styles()->registered['theme-style']; // Including the version number is crucial. $path_to_theme_styles = $wp_style_theme->src . '?ver=' . $wp_style_theme->ver; $preload_resources[] = array( 'href' => $path_to_theme_styles, 'as' => 'style', 'media' => 'all', 'type' => 'text/css', ); } return $preload_resources; } add_filter( 'wp_preload_resources', 'craftedat_preload_assets' ); Log in to add feedback

Параметры

$preload_resources array обязательный
Массив ресурсов и их атрибутов либо URL-адресов для вывода предзагрузки ресурсов. ...$0 array Массив атрибутов ресурса. href stringURL для включения в предзагрузку ресурсов. Обязательный. as stringКак браузер должен обрабатывать ресурс (script, style, image, document и т.д.). crossorigin stringУказывает политику CORS для заданного ресурса. type stringТип ресурса (text/html, text/css и т.д.). media stringПринимает типы носителей или медиазапросы. Позволяет адаптивную предзагрузку. imagesizes stringАдаптивный размер источника для source set. imagesrcset stringАдаптивные источники изображений для source set. fetchpriority stringЗначение fetchpriority для ресурса. Source $preload_resources = apply_filters( 'wp_preload_resources', array() ); View all references View on Trac View on GitHub Related Used byDescriptionwp_preload_resources()wp-includes/general-template.phpВыводит директивы предзагрузки ресурсов в браузеры. Changelog VersionDescription6.6.0Added the $fetchpriority attribute.6.1.0Introduced. User Contributed Notes Skip to note 2 content Robert C. 2 years ago You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Вот как можно использовать фильтр wp_preload_resources для предзагрузки стилей вашей темы. function craftedat_preload_assets( array $preload_resources ): array { /** * Check if stylesheet is loaded. * 'theme-style' is the WP handle of your stylesheet. */ if ( wp_style_is( 'theme-style' ) ) { $wp_style_theme = wp_styles()->registered['theme-style']; // Including the version number is crucial. $path_to_theme_styles = $wp_style_theme->src . '?ver=' . $wp_style_theme->ver; $preload_resources[] = array( 'href' => $path_to_theme_styles, 'as' => 'style', 'media' => 'all', 'type' => 'text/css', ); } return $preload_resources; } add_filter( 'wp_preload_resources', 'craftedat_preload_assets' ); Log in to add feedback

Исходный код

wp-includes/general-template.php:3787

$preload_resources = apply_filters( 'wp_preload_resources', array() );

История изменений

ВерсияОписание
6.6.0 Added the $fetchpriority attribute.
6.1.0 Introduced.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.