Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Inline Css Rules injected through Woocommerce into Head Section (woocommerce-inline-inline-css)

Woocommerce injects the following inline css rule into the head section of my theme. Any idea how to remove it through my child themes functions.php?

    <style id='woocommerce-inline-inline-css' type='text/css'>.woocommerce form .form-row .required { visibility: visible; }</style>

If im not missing anything the following code block in the woocommerce plugins file ...woocommerce-includes/class-wc-frontend-scripts.php is responsible for it.

    // Placeholder style.
    wp_register_style( 'woocommerce-inline', false ); // phpcs:ignore
    wp_enqueue_style( 'woocommerce-inline' );

    if ( true === wc_string_to_bool( get_option( 'woocommerce_checkout_highlight_required_fields', 'yes' ) ) ) {
        wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: visible; }' );
    } else {
        wp_add_inline_style( 'woocommerce-inline', '.woocommerce form .form-row .required { visibility: hidden; }' );
    }
like image 833
evavienna Avatar asked Aug 30 '26 17:08

evavienna


1 Answers

The following action removes

<style id='woocommerce-inline-inline-css' type='text/css'>.woocommerce form .form-row .required { visibility: visible; }</style>

from the head section. Code goes into your functions.php file of your child or parent theme.

Input from O. Jones in the comments: Or, consider using the Code Snippets plugin to hold these small tweaks to a site. If you edit functions.php you may (a) have it overwritten by an update, (b) possibly lose track of where you put your tweaks.

        // Remove the following from head section - see source code
        // <style id='woocommerce-inline-inline-css' type='text/css'>.woocommerce form .form-row .required { visibility: visible; }</style>
        add_action('wp_enqueue_scripts', 'remove_woo_inline_css_head_ac',11);
            function remove_woo_inline_css_head_ac() {
            wp_deregister_style( 'woocommerce-inline' );
        }
like image 84
evavienna Avatar answered Sep 01 '26 05:09

evavienna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!