Support » Theme: Twenty Twenty-One » Parent theme style loaded after child style

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    You can please remove/replace your code with below in your child theme functions.php

    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        $parenthandle = 'twenty-twenty-one-style'; // This is 'twenty-twenty-one-style' for the Twenty Twenty-one theme.
        $theme = wp_get_theme();
        wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css', 
            array(),  // if the parent theme code has a dependency, copy it to here
            $theme->parent()->get('Version')
        );
        wp_enqueue_style( 'custom-style', get_stylesheet_uri(),
            array( $parenthandle ),
            $theme->get('Version') // this only works if you have Version in the style header
        );
    }
    Thread Starter szazo74

    (@szazo74)

    Thank you, Mukesh

    This is what I use in functions.php (but I am going to replace with your suggestion):

    add_action( 'wp_enqueue_scripts', 'enqueue_parent_theme_style' );
    function enqueue_parent_theme_style() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
    }
    
    function theme_styles() 
    {
    	wp_register_style('custom-styles', get_stylesheet_directory_uri() . '/mystyle.css' );
    	wp_enqueue_style('custom-styles');
    
    }
    add_action( 'wp_enqueue_scripts', 'theme_styles' );
    • This reply was modified 1 month, 2 weeks ago by szazo74.
    • This reply was modified 1 month, 2 weeks ago by t-p. Reason: Code formated
    Thread Starter szazo74

    (@szazo74)

    THANK YOU, it works! 🙂

    rcecilwp

    (@rcecilwp)

    I just made an account to say THANK YOU. I was having so much trouble with this, and you you @mukesh27 solved it.

    Thank you @rcecilwp

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.