Filter hook 'wp_preload_resources'

in WP Core File wp-includes/general-template.php at line 3762

View Source

wp_preload_resources

Filter Hook
Description
Filters domains and URLs for resource preloads. Array of resource attributes. (`script`, `style`, `image`, `document`, etc). } }

Hook Information

File Location wp-includes/general-template.php View on GitHub
Hook Type Filter
Line Number 3762

Hook Parameters

Type Name Description
array $preload_resources { Array of resources and their attributes, or URLs to print for resource preloads.

Usage Examples

Basic Usage
<?php
// Hook into wp_preload_resources
add_filter('wp_preload_resources', 'my_custom_filter', 10, 1);

function my_custom_filter($preload_resources) {
    // Your custom filtering logic here
    return $preload_resources;
}

Source Code Context

wp-includes/general-template.php:3762 - How this hook is used in WordPress core
<?php
3757  	 *         @type string $imagesrcset   Responsive image sources to the source set.
3758  	 *         @type string $fetchpriority Fetchpriority value for the resource.
3759  	 *     }
3760  	 * }
3761  	 */
3762  	$preload_resources = apply_filters( 'wp_preload_resources', array() );
3763  
3764  	if ( ! is_array( $preload_resources ) ) {
3765  		return;
3766  	}
3767  

PHP Documentation

<?php
/**
	 * Filters domains and URLs for resource preloads.
	 *
	 * @since 6.1.0
	 * @since 6.6.0 Added the `$fetchpriority` attribute.
	 *
	 * @param array  $preload_resources {
	 *     Array of resources and their attributes, or URLs to print for resource preloads.
	 *
	 *     @type array ...$0 {
	 *         Array of resource attributes.
	 *
	 *         @type string $href          URL to include in resource preloads. Required.
	 *         @type string $as            How the browser should treat the resource
	 *                                     (`script`, `style`, `image`, `document`, etc).
	 *         @type string $crossorigin   Indicates the CORS policy of the specified resource.
	 *         @type string $type          Type of the resource (`text/html`, `text/css`, etc).
	 *         @type string $media         Accepts media types or media queries. Allows responsive preloading.
	 *         @type string $imagesizes    Responsive source size to the source Set.
	 *         @type string $imagesrcset   Responsive image sources to the source set.
	 *         @type string $fetchpriority Fetchpriority value for the resource.
	 *     }
	 * }
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/general-template.php
Related Hooks

Related hooks will be displayed here in future updates.