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

block editor - Removing unnecessary CSS and JS code from wp_head()

programmeradmin4浏览0评论

I am using Wordpress in headless mode and write articles using Gutenberg, for convenience. I am also using third-party plugins that I need to embed on the page and for this I use the wp_head() function to include the plugins' stylesheets. However, the output of wp_head() also returns a lot of code that I don't need and would like to remove:

<style>img:is([sizes="auto" i], [sizes^="auto," i]) { contain-intrinsic-size: 3000px 1500px }</style>
<script>
window._wpemojiSettings = {"baseUrl":"https:\/\/s.w\/images\/core\/
//code
</script>
<style id='wp-block-paragraph-inline-css'>
//code
</style>
<style id='wp-block-table-inline-css'>
//code
</style>
<style id='wp-block-heading-inline-css'>
//code
</style>
<style id='wp-block-quote-inline-css'>
//code
</style>
<style id='wp-emoji-styles-inline-css'>
    //code
</style>
<style id='wp-block-library-inline-css'>
//code
</style>
<style id='global-styles-inline-css'>
//code
</style>
<script type="text/javascript">
                // Notice how this gets configured before we load Font Awesome
                window.FontAwesomeConfig = { autoReplaceSvg: false }
            </script>
        <style class='wp-fonts-local'>
//code
</style>

I've tried these commands but haven't quite solved it: I can only remove the theme stylesheets and a few other code snippets, but not the code that relates to Gutenberg.:

// Removes the wlwmanifest link
remove_action( 'wp_head', 'wlwmanifest_link' );
// Removes the RSD link
remove_action( 'wp_head', 'rsd_link' );
// Removes the WP shortlink
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
// Removes the canonical links
remove_action( 'wp_head', 'rel_canonical' );
// Removes the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links_extra', 3 ); 
// Removes links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'feed_links', 2 ); 
// Removes the index link
remove_action( 'wp_head', 'index_rel_link' ); 
// Removes the prev link
remove_action( 'wp_head', 'parent_post_rel_link' ); 
// Removes the start link
remove_action( 'wp_head', 'start_post_rel_link' ); 
// Removes the relational links for the posts adjacent to the current post
remove_action( 'wp_head', 'adjacent_posts_rel_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );
// Removes the WordPress version i.e. -
remove_action( 'wp_head', 'wp_generator' );

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
remove_action('rest_api_init', 'wp_oembed_register_route');

add_action('wp_enqueue_scripts', function() {

  wp_dequeue_style('parent-style');
  wp_deregister_style('parent-style');

  wp_dequeue_style('child-style');
  wp_deregister_style('child-style');

  wp_dequeue_style( 'wp-block-library' );
  wp_dequeue_style( 'wp-block-library-theme' );
  wp_dequeue_style( 'wc-block-style' ); 
  wp_dequeue_style( 'global-styles' );
    
    wp_dequeue_style('storefront-gutenberg-blocks');  styles

 
  wp_dequeue_style( 'classic-theme-styles' );

  wp_dequeue_style('twentytwentyfive-style');
  wp_deregister_style('twentytwentyfive-style');

}, 100);

What can I do?

发布评论

评论列表(0)

  1. 暂无评论