• Hello,
    i’m looking for a way to remove svg filter that are printed in wp_footer since WP 5.9

    
    <svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 0 0" width="0" height="0" focusable="false" role="none" style="visibility: hidden; position: absolute; left: -9999px; overflow: hidden;" ><defs><filter id="wp-duotone-dark-grayscale">...
    

    Thank you very much

Viewing 3 replies - 1 through 3 (of 3 total)
  • It’s a known issue right now for the block editor, and it will be fixed in the future release.

    https://github.com/WordPress/gutenberg/issues/38299

    There’s a workaround. If you are not using the block editor, you can add this code to your theme’s functions.php

    add_action('after_setup_theme', function () {
    	remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');
    	remove_action('wp_footer', 'wp_enqueue_global_styles', 1);
    }, 10, 0);

    However, if you use the block editor, the workaround above can break some of your page’s styling. If that happens, I suggest using this code instead (in your theme’s functions.php).

    add_action('wp_footer',function() {
            global $wp_filter;
    
            if(empty($wp_filter['wp_footer'][10])) return;
    
            foreach($wp_filter['wp_footer'][10] as $hook) {
                    if(!is_object($hook['function']) || get_class($hook['function']) !== 'Closure') continue;
    
                    $static=(new ReflectionFunction($hook['function']))->getStaticVariables();
    
                    if(empty($static['svg'])) continue;
    
                    if(!str_starts_with($static['svg'],'<svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 0 0" ')) continue;
    
                    remove_action('wp_footer',$hook['function'],10);
            }
    },9);
    Thread Starter Colir

    (@colir)

    Thank you.
    I’ll try this next week.

    Cambabutonono

    (@cambabutonono)

    That workaround works! Removes both default inline css and the filters from the footer.

    Not sure why all that garbage is included by default anyway, should be added by a theme imho.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Remove SVG FIlter’ is closed to new replies.