php 删除style.css删除父主题css

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 删除style.css删除父主题css相关的知识,希望对你有一定的参考价值。

https://wordimpress.com/removing-styles-scripts-from-your-wordpress-parent-theme/


Using code: Here’s an excellent function from Ngoc Nguyen that will print out the script handles. You can insert this into a page template, create a page with that template, then visit that page and you’ll see the list output really nicely on the page. Just make sure you don’t use this on a live site:

function wpcustom_inspect_scripts_and_styles() {
 global $wp_scripts;
 global $wp_styles;
 
 // Runs through the queue scripts
 foreach( $wp_scripts->queue as $handle ) :
 $scripts_list .= $handle . ' | ';
 endforeach;
 
 // Runs through the queue styles
 foreach( $wp_styles->queue as $handle ) :
 $styles_list .= $handle . ' | ';
 endforeach;
 
 printf('Scripts: %1$s  Styles: %2$s', 
 $scripts_list, 
 $styles_list);
}
 
add_action( 'wp_print_scripts', 'wpcustom_inspect_scripts_and_styles' );


How Do I De-Enqueue the Scripts?

Now that you have the handles of the styles or scripts that you want to de-enqueue, you’ve got to actually de-enqueue them. Here’s a few methods for doing that.
Using Code

I prefer to use code to keep the plugins to a minimum. Fortunately, de-enqueuing scripts and styles in WordPress is very easy. Add this to your custom functionality plugin:

/**
 * Dequeue the Parent Theme scripts.
 *
 * Hooked to the wp_print_scripts action, with a late priority (100),
 * so that it is after the script was enqueued.
 */
function my_site_WI_dequeue_script() {
 wp_dequeue_script( 'comment-reply' ); //If you're using disqus, etc.
 wp_dequeue_script( 'jquery_ui' ); //jQuery UI, no thanks!
 wp_dequeue_script( 'fancybox' ); //Nah, I use FooBox
 wp_dequeue_script( 'wait_for_images' );
 wp_dequeue_script( 'jquery_easing' );
 wp_dequeue_script( 'swipe' );
 wp_dequeue_script( 'waypoints' );
}
 
add_action( 'wp_print_scripts', 'my_site_WI_dequeue_script', 100 );
 
/**
 * Dequeue the Parent Theme styles.
 *
 * Hooked to the wp_enqueue_scripts action, with a late priority (100),
 * so that it runs after the parent style was enqueued.
 */
 
function give_dequeue_plugin_css() {
    wp_dequeue_style('additional-parent-style');
    wp_deregister_style('additional-parent-style');
}
add_action('wp_enqueue_scripts','give_dequeue_plugin_css', 100);

以上是关于php 删除style.css删除父主题css的主要内容,如果未能解决你的问题,请参考以下文章

当需要使用archives.php页面时

WordPress主题制作:子主题(Child Theme)

如何使用 Webpack 删除/取消导入内联 CSS?

css WordPress - 儿童主题 - style.css模板

如何在WordPress page.php,single.php中加载style.css根目录

css 用于开发WordPress主题的style.css模板