This functionality is available for PRO version.
Name: wp-hide/module/general_css_combine/add_media_query
Type: Filter
Arguments:
(bool) $add_media_query
(text) $code_block
The wp-hide/module/general_css_combine/add_media_query filter allows you to control whether the @media queries are included in the processed CSS assets by the WP Hide plugin. By default, the plugin adds @media data to the combined CSS files. However, using this filter, you can modify this behavior based on specific conditions.
The following example demonstrates how to use the wp-hide/module/general_css_combine/add_media_query filter. It checks if the $code_block contains a specific string related to media loading and disables the addition of @media queries if the condition is met.
add_filter ( 'wp-hide/module/general_css_combine/add_media_query', 'wp_hide_module_general_css_combine_add_media_query', 10, 2 );
function wp_hide_module_general_css_combine_add_media_query ( $add_media_query, $code_block )
{
if ( $add_media_query && stripos( $code_block, 'onload="this.onload=null;this.media=\'all\'') )
$add_media_query = FALSE;
return $add_media_query;
}
Explanation
- Filter Hook: The
add_filter
function is used to attach thewp_hide_module_general_css_combine_add_media_query
function to thewp-hide/module/general_css_combine/add_media_query
filter hook. - Function Definition: The
wp_hide_module_general_css_combine_add_media_query
function takes two parameters:$add_media_query
and$code_block
. - Condition Check: Inside the function, a condition checks if
$add_media_query
isTRUE
and if$code_block
contains the stringonload="this.onload=null;this.media='all'
. - Modify $add_media_query: If the condition is met,
$add_media_query
is set toFALSE
, indicating that @media queries should not be added. - Return Value: The modified value of
$add_media_query
is returned.
Usage Context
This filter can be particularly useful when you want to exclude @media queries from the combined CSS based on specific criteria. For instance, you might have certain CSS blocks that should not have @media queries added due to specific loading behaviors or optimizations.
By implementing this filter, you gain finer control over the CSS combining process in the WP Hide plugin, allowing for more customized and optimized handling of your site’s stylesheets.
Important!
The above code should be placed within wp-content/mu-plugins/ directory.
The above filter is included in the PostProcessing Replacements component.