This is the bottom half of my child theme's functions.php.
function register_my_scripts(){
if (is_shop() || is_product_category()){
wp_enqueue_style( 'shop-style', get_stylesheet_directory_uri() .
'/shop.css');
}
if (is_product()){
wp_enqueue_style( 'shop-style', get_stylesheet_directory_uri() .
'/product.css');
}
}
add_action( 'wp_enqueue_scripts', 'register_my_scripts' );
Why is it, when I have the following code in the same file (above it), then the style enqueues in the above code block (but below on my file) stop working, even though the 'if' block still runs (I tested with "echo 'something';" and the echo ran)?
function register_my_menu() {
register_nav_menu('left-menu', __('Left Menu'));
register_nav_menu('right-menu', __('Right Menu'));
wp_enqueue_style( 'shop-style', get_stylesheet_directory_uri() .
'/shop.css');
}
But when i comment out the wp_enqueue_style in the same line, so the whole file looks like:
function register_my_menu() {
register_nav_menu('left-menu', __('Left Menu'));
register_nav_menu('right-menu', __('Right Menu'));
// wp_enqueue_style( 'shop-style', get_stylesheet_directory_uri() .
'/shop.css');
}
add_action( 'init', 'register_my_menu');
function register_my_scripts(){
// wp_enqueue_style( 'shop-style', get_stylesheet_directory_uri() .
'/shop.css');
if (is_shop() || is_product_category()){
wp_enqueue_style( 'shop-style', get_stylesheet_directory_uri() .
'/shop.css');
}
if (is_product()){
wp_enqueue_style( 'shop-style', get_stylesheet_directory_uri() .
'/product.css');
}
}
add_action( 'wp_enqueue_scripts', 'register_my_scripts' );
The enqueues in register_my_scripts()
runs properly again.
This is a conflict that I have never seen anywhere, and why the hell doesn't WordPress throw some kind of error. It's hellish to debug these things.
Is there a strict version of WordPress I can get somewhere, like JavaScript's "use strict"?
The fact that they never throw any errors is sickening.