I have a notmytheme, the original css load order is like so:
<link rel='stylesheet' id='something' href='http://localhost/mywp/wp-content/themes/notmytheme/something.css' type='text/css' media='all' />
<link rel='stylesheet' id='notmytheme-style-css' href='http://localhost/mywp/wp-content/themes/notmytheme/style.css?ver=1.0.9' type='text/css' media='all' />
When I created a child theme called the notmytheme-child, and enqueue the child style, it became like this:
<link rel='stylesheet' id='notmytheme-style-css' href='http://localhost/mywp/wp-content/themes/notmytheme/style.css?ver=1.0.9' type='text/css' media='all' />
<link rel='stylesheet' id='child-style-css' href='http://localhost/mywp/wp-content/themes/notmytheme-child/style.css?ver=18.08.07' type='text/css' media='all' />
<link rel='stylesheet' id='something' href='http://localhost/mywp/wp-content/themes/notmytheme/something.css' type='text/css' media='all' />
I want the parent and child style to be loaded after other styles like how the parent theme did it, so I moved it down with priority ( add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 999 );
), now it became like this:
<link rel='stylesheet' id='something' href='http://localhost/mywp/wp-content/themes/notmytheme/something.css' type='text/css' media='all' />
<link rel='stylesheet' id='notmytheme-style-css' href='http://localhost/mywp/wp-content/themes/notmytheme-child/style.css?ver=1.0.9' type='text/css' media='all' />
<link rel='stylesheet' id='child-style-css' href='http://localhost/mywp/wp-content/themes/notmytheme-child/style.css?ver=18.08.07' type='text/css' media='all' />
I do not know why but now the get_template_directory_uri()
now points to notmytheme-child instead of notmytheme.
My current enqueue script is like so:
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 999 );
function my_theme_enqueue_styles() {
$parent_style = 'notmytheme-style';
wp_enqueue_style( $parent_style,
get_template_directory_uri() . '/style.css',
array(),
'1.0.9' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
'18.08.07',
'all' );
}
Adjusting the priority changes the position of where the css are loaded, and also which directory get_template_directory_uri()
points to.
EDIT/SOLUTION
My codes are now:
add_action( 'wp_enqueue_scripts', 'my_enqueue_child', 999 );
function my_enqueue_child() {
wp_dequeue_style( 'notmytheme-style' );
wp_enqueue_style( 'parent-style',
get_template_directory_uri() . '/style.css',
array(),
'1.0.9' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( 'parent-style' ),
'18.08.07',
'all' );
}
notmytheme
andnotmytheme-style
the actual values in your code? Or examples? What's your parent theme's actual name? How does the parent theme enqueue its stylesheet? – Jacob Peattie Aug 7 '18 at 6:48