wp_enqueue_style( $parent_style, get_stylesheet_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
Look closer, specifically at the URLs you passed to enqueue style:
- parent:
get_stylesheet_directory_uri() . '/style.css' - child:
get_stylesheet_directory_uri() . '/style.css'
They’re identical, they’re the same file, that’s the problem. Your child themes stylesheet isn’t overriding the parent, because the parent is never loaded, your code never tells WP to load it.
Some notes:
- Use
get_template_directory_urito refer to the parent theme, andget_stylesheet_directory_urifor the child theme - indent, indent, indent, you’ve not indented your arguments, this is important
- You declared the parent stylesheet as a dependency of the child, but you’ve already enqueued it, register the parent, then enqueue the child and it’ll have the same impact
- You’re using the theme version as the version for the stylesheet, but it would be more efficient to use the file modification time else you’ll have to flush browser cache during development
get_stylesheet_uri()returns the full path to thestyle.cssso the.'/style.css'is unnecessary- The
$parent_stylevariable is unnecessary