最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to print all the inline styles in the WP_Styles instance together with their keys?

programmeradmin4浏览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!

发布评论

评论列表(0)

  1. 暂无评论