admin管理员组文章数量:1122832
I got problems with my twentytwenty child theme and hope, that someone can help me.
In order to optimize my website for speed, I'd like to use critical css as inline code. To do that, I wanted to call style.css asynchronously, what means I have to set it in header.php manually, without using wp_enqueue_style.
When I created the child theme in the past, I unfortunately copied the whole parent theme and made several modifications. That's the reason, why I'm disabling the parent theme complete, to avoid double loading of these big style files.
With the following code in functions.php I disabled the parent theme and enqueued the child theme:
function child_theme_styles()
{
wp_dequeue_style( 'twenty-twenty-style' );
wp_deregister_style( 'twenty-twenty-style' );
wp_enqueue_style('twentytwenty-child-style', get_stylesheet_directory_uri() . '/style.css', array('twentytwenty-style'));
}
add_action('wp_enqueue_scripts', 'child_theme_styles');
Strangely, the following line is still being loaded in head (which is not the real problem though):
<link rel="stylesheet" id="twentytwenty-print-style-css" href=".css?ver=6e696dca833adce1dfc8a4b185ba1bf1" media="print">
The actual problem is, that I'm not able to disable enqueuing the child theme style.css, to place the code manually in header.php. When I comment out or delete the last line in the mentioned function, the style.css of my child theme is still loaded (see screenshot below)!
wp_enqueue_style('twentytwenty-child-style', get_stylesheet_directory_uri() . '/style.css', array('twentytwenty-style'));
There is no other custom code, that is loading this line. So, how can this happen? What is the right way to stop my child styles from loading automatically?
I got problems with my twentytwenty child theme and hope, that someone can help me.
In order to optimize my website for speed, I'd like to use critical css as inline code. To do that, I wanted to call style.css asynchronously, what means I have to set it in header.php manually, without using wp_enqueue_style.
When I created the child theme in the past, I unfortunately copied the whole parent theme and made several modifications. That's the reason, why I'm disabling the parent theme complete, to avoid double loading of these big style files.
With the following code in functions.php I disabled the parent theme and enqueued the child theme:
function child_theme_styles()
{
wp_dequeue_style( 'twenty-twenty-style' );
wp_deregister_style( 'twenty-twenty-style' );
wp_enqueue_style('twentytwenty-child-style', get_stylesheet_directory_uri() . '/style.css', array('twentytwenty-style'));
}
add_action('wp_enqueue_scripts', 'child_theme_styles');
Strangely, the following line is still being loaded in head (which is not the real problem though):
<link rel="stylesheet" id="twentytwenty-print-style-css" href="https://www.mydomain.de/wp-content/themes/twentytwenty/print.css?ver=6e696dca833adce1dfc8a4b185ba1bf1" media="print">
The actual problem is, that I'm not able to disable enqueuing the child theme style.css, to place the code manually in header.php. When I comment out or delete the last line in the mentioned function, the style.css of my child theme is still loaded (see screenshot below)!
wp_enqueue_style('twentytwenty-child-style', get_stylesheet_directory_uri() . '/style.css', array('twentytwenty-style'));
There is no other custom code, that is loading this line. So, how can this happen? What is the right way to stop my child styles from loading automatically?
Share Improve this question edited Mar 27, 2024 at 8:45 Andreas Böttcher asked Mar 27, 2024 at 8:38 Andreas BöttcherAndreas Böttcher 112 bronze badges1 Answer
Reset to default 0I solved the problem myself with this code:
function remove() {
wp_dequeue_style( 'twentytwenty-style' );
wp_deregister_style( 'twentytwenty-style' );
wp_dequeue_style('twentytwenty-child-style', get_stylesheet_directory_uri() . '/style.css', array('twentytwenty-child-style'));
wp_dequeue_style( 'twentytwenty-print-style' );
wp_deregister_style( 'twentytwenty-print-style' );
}
add_action( 'wp_print_styles', 'remove', 100 );
本文标签: Can39t disable child theme style
版权声明:本文标题:Can't disable child theme style 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736312327a1935061.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论