• Resolved Csaba (LittleBigThings)

    (@littlebigthing)


    Hi,

    I am building a child theme for the Twenty Twenty-One theme. The child theme style.css is modified and compiled from the SASS of the parent theme. Therefore, I would like to load the child theme’s style.css only. This does not seem to work.

    The parent theme loads its style sheet using get_template_directory_uri(), which is probably the reason for the problem: I don’t seem to be able to dequeue the parent style via the usual way. Both style sheets are loaded, I can only influence the order (which is not really useful :-)).

    Is there a best (or better :-)) practice to dequeue a parent style when it is loaded using get_template_directory_uri()?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You can do it, but the child is loaded before the parent. So you have to use the priority parameter of add_action to make sure your dequeue runs after the parent’s enqueue. See Child Themes.

    Thread Starter Csaba (LittleBigThings)

    (@littlebigthing)

    Thanks! The clue was (obviously) not making the parent style a dependency when enqueueing the child theme style.css and indeed setting the priority higher than 10.

    For anyone having the same issue, I have used the following code in my child theme’s functions.php:

    function child_enqueue_styles() {
    
    	// dequeue the Twenty Twenty-One parent style
    	wp_dequeue_style( 'twenty-twenty-one-style' );
        
    	// Theme stylesheet
    	wp_enqueue_style( 'child-style', get_stylesheet_uri(), array(), wp_get_theme()->get('Version') );
    
    }
    add_action( 'wp_enqueue_scripts', 'child_enqueue_styles', 11 );

    Let′s assume I have a stylesheet that is loading from an external source like a font and it′s located on my HTML like this…

    <link rel=’stylesheet’ id=’google-fonts-1-css’ href=’https://fonts.googleapis.com/css?.. and a bunch of parameters for the font family.

    So, how can I apply your formula for me to unload or dequeue this style sheet from rendering?

    By the way, I am also using a child theme…Thanks!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dequeue parent style that is enqueued with get_template_directory_uri()’ is closed to new replies.