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" 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 (wp_enqueue_style(‘twentytwenty-child-style’ …), the style.css of my child theme is still loaded as <link> in the head:
<link rel="stylesheet" id="twentytwenty-style-css" media="all">
There is no other custom code, that is loading this style. So, how can this happen? What is the right way to stop my child styles from loading automatically?
Thank you very much for your help in advance!
Andreas
This is how I registered and enqueued this new stylesheet
// Stylesheet for MemberPress Classroom
function ly_register_classroom_style(){
wp_register_style( 'ly-classroom-style', get_stylesheet_directory_uri() . 'assets/css/ly-memberpress-style.css' );
wp_enqueue_style( 'ly-classroom-style',
get_stylesheet_directory_uri() . 'assets/css/ly-memberpress-style.css',
array( 'child-style' ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'ly_register_classroom_style' );
And this is the filter I added below, provided by MemberPress support
add_filter('mpcs_classroom_style_handles',
function($allowed_handles){
$allowed_handles[] = 'ly-classroom-style';
return $allowed_handles;
}
);
It’s not working…
What am I missing? What am I doing wrong?
Thank you so much in advanced!
PS: If I add the CSS in the customizer, my style is applied. But I wrote so many lines that I’d like to have this on a separate stylesheet
]]>Could you suggest a sample hook snippet to enqueue a stylesheet only on pages were a lazy block is used?
P.S. I want to thank you for your tremendous contribution to the WP community. This plugin, Ghost Kit and DocPress are all excellent (and much needed) plugins. Thanks so much!
]]>Premium theme: Kallyas theme
I am using 3 plugins for optimization:
1) Smush pro for image optimization and CDN
2) WP-Rocket for caching etc
3) Asset CleanUp: Page Speed Booster
4) Also use cloudflare (Free plan) for the rest of the static assets.
(No conflicts between them.)
I also want to use OMFG to serve google fonts locally.
The problem is that when i install the plugin and try to get the list of the fonts that appear in my theme, there are no fonts that appear in the list at all.
I have purged all the caches, i have even desabled al the plugins and purged all the caches, but still the list with the fonts, does not appear at all if i click the “Save and optimize” button.
The method of optimization is set to manual.
how do you advice, in order to debug the issue?
Best Regards
]]>when i make a child theme using a professional theme, the parent css styles are still loaded along with child styles.
but when i make a child theme using a very simple theme i create myself (bare minimum index, style, screenshot), i can get the child styles to load but not the parent’s.
i’ve been following these instructions:
https://developer.www.ads-software.com/themes/advanced-topics/child-themes/#3-enqueue-stylesheet very closely and still… no love.
i’d really like to understand how this works.
thank you <3,
]]>add_action('wp_enqueue_scripts', 'tbt_enqueue_styles');
function tbt_enqueue_styles()
{
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('style', get_stylesheet_directory_uri() . '/style.css', array(), filemtime(get_stylesheet_directory() . '/style.css'));
}
(Basically, using the file modified time to generate a string.)
This is working in so much as is enqueues the stylesheet with the expected ?ver= string appended to it. The problem is, it inserts it too early in in the html <head> so several styles are being overridden by a later stylesheets.
If I don’t enqueue the stylesheet in functions.php, WordPress does it automatically and puts it in the correct order (near the end), but I loose the cachebuster.
So I have two questions I’m hoping someone here can help me with
1. What determines where in the list of stylesheets the default theme style.css file goes when it’s not explicitly enqueued? and
2. How can I enqueue my own stylesheet at that position?
With child themes and in functions.php, when you add this wp_enqueue_style( ‘child-style’===> should child-style be the named of the folder of the child theme? i.e. should child-style be myfoo-style because the name of my child theme folder is called myfoo?
function my_theme_enqueue_styles() {
//$parent_style = ‘parent-style’; // This is ‘twentynineteen-style’ for the Twenty nineteen theme.
$parent_style = ‘twentynineteen-style’;
wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/style.css’ );
wp_enqueue_style( ‘child-style’,
get_stylesheet_directory_uri() . ‘/style.css’,
array( $parent_style ),
wp_get_theme()->get(‘Version’)
);
}
add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
]]>I get an error when debagging the Query Monitor plugin that the theme ” OceanWP “is trying to display styles with id “oceanwp-woocommerce” and “slick”. The fact is that the theme uses the wp_enqueue_style() function, and in the plugin they are canceled not through wp_dequeue_style(), but through wp_deregister_style(). This is logically incorrect and generates such an error.
Am I speaking correctly?
]]>I am wondering if the notice is talking about the enqueue statements in Aaron’s functions.php file since I’m not enqueueing anything now. Here is the notice:
]]>PHP Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the
wp_enqueue_scripts
,admin_enqueue_scripts
, orlogin_enqueue_scripts
hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /home/stcwdc57/public_html/dev.stcwdc.org/wp-includes/functions.php on line 4161