• Resolved wpublish2

    (@wpublish2)


    I can see this exclusion field on CSS Options: Exclude CSS from Autoptimize.

    This field allows to exclude files of being optimized.

    But, do your awesome plugin has a filter to exclude a specific style from compilation by its “handle” name? For example, I have this inline style:

    wp_register_style( 'cpxt-loading-handle', false );
    wp_enqueue_style( 'cpxt-loading-handle' );
    wp_add_inline_style( 'cpxt-loading-handle', $css_code );

    This will magically force WordPress to add the ‘cpxt-loading-handle’ inline style without depend of a parallel CSS file enqueue.

    The handle name in this case: ‘cpxt-loading-handle’.

    I’m looking by something like this:

    add_filter( 'autoptimize_filter_handle_css', 'cpxt_exclude_handles_from_autoptimize', 10 , 1 );
    
    function cpxt_exclude_handles_from_autoptimize( $handles_array ) {
    
    	$key = array_search( 'cpxt-loading-handle', $handles_array );
    
    	if( false !== $key ) {
        		unset( $handles_array[ $key ] );
    	}
    
    	return $handles_array;
    }

    Waiting your feedback, thanks in advance.

    • This topic was modified 5 years, 5 months ago by wpublish2.
Viewing 1 replies (of 1 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    Afraid AO extracts CSS and excluded purely based on HTML, so enqueuing and scripts and styles has already been done and AO does not know about handles. What you could do (as when registering you *know* the $css_code, is add a substring of $css_code to the exclusion list using the API, hooking into autoptimize_filter_css_exclude?

    hope this helps,
    frank

Viewing 1 replies (of 1 total)
  • The topic ‘Remove a certain style by its enqueue handle name’ is closed to new replies.