Filter hook 'wp_loading_optimization_force_header_contexts'

in WP Core File wp-includes/media.php at line 6102

View Source

wp_loading_optimization_force_header_contexts

Filter Hook
Description
Filters the header-specific contexts.

Hook Information

File Location wp-includes/media.php View on GitHub
Hook Type Filter
Line Number 6102

Hook Parameters

Type Name Description
array $default_header_enforced_contexts Map of contexts for which elements should be considered in the header of the page, as $context => $enabled pairs. The $enabled should always be true.

Usage Examples

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

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

Source Code Context

wp-includes/media.php:6102 - How this hook is used in WordPress core
<?php
6097  		 *
6098  		 * @param array $default_header_enforced_contexts Map of contexts for which elements should be considered
6099  		 *                                                in the header of the page, as $context => $enabled
6100  		 *                                                pairs. The $enabled should always be true.
6101  		 */
6102  		$header_enforced_contexts = apply_filters( 'wp_loading_optimization_force_header_contexts', $header_enforced_contexts );
6103  
6104  		// Consider elements with these header-specific contexts to be in viewport.
6105  		if ( isset( $header_enforced_contexts[ $context ] ) ) {
6106  			$maybe_in_viewport    = true;
6107  			$maybe_increase_count = true;

PHP Documentation

<?php
/**
		 * Filters the header-specific contexts.
		 *
		 * @since 6.4.0
		 *
		 * @param array $default_header_enforced_contexts Map of contexts for which elements should be considered
		 *                                                in the header of the page, as $context => $enabled
		 *                                                pairs. The $enabled should always be true.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/media.php
Related Hooks

Related hooks will be displayed here in future updates.