0

I have read this but I see that $wp_styles->registered contains only external stylesheets.

I am also trying to understand WP works. I am writing a theme from scratch. I believe that the unwanted inline styles are not caused by plugins (I have only 2 installed: Duplicator and Prevent Browser Caching, both updated).

The inline style that I do not want is this (taken from Chrome DevTools):

<style type="text/css" media="screen">
    html { margin-top: 32px !important; }
    * html body { margin-top: 32px !important; }
    @media screen and ( max-width: 782px ) {
        html { margin-top: 46px !important; }
        * html body { margin-top: 46px !important; }
    }
</style>

The theme contains just 3 files. index.php and style.css are just static files currently. Here is my functions.php (nothing original):

<?php

/**
 * Theme Functions
 */
function theme_name_scripts() {
    wp_enqueue_style( 'style', get_stylesheet_uri() );

}

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

/**
 * Remove the inline styles of the theme.
 */
add_action( 'wp_enqueue_scripts', function() {
    global $wp_styles;
    foreach ($wp_styles->registered as $val) {
        echo "CSS: " . $val->handle . " at " . $val->src . " \n";
   }
    // $styles = wp_styles();
    // $styles->add_data( 'twentytwenty-style', 'after', array() );
}, 20 );

Thank you!

3
  • 1
    that inline style is for and from the admin bar/toolbar - disable the toolbar for the front - via 'Users' - 'Your Profile' - Toolbar [ ] Show Toolbar when viewing site.
    – Michael
    Apr 1, 2020 at 17:45
  • @Michael It worked. Thank you! Apr 3, 2020 at 8:03
  • @Michael You can post an answer and I will accept it. Apr 6, 2020 at 10:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.