Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress admin_enqueue_scripts not working

I have this code below and it seems not working:

function load_custom_wp_admin_style() {
    wp_register_style( 'custom_wp_admin_css', get_stylesheet_directory_uri() . '/admin-style.css', false, '1.0.0' );
    wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );

But when I replace it with wp_enqueue_scripts instead of admin_enqueue_scripts then it will load the file. I'm not sure what's the issue.

like image 753
Randy Avatar asked Dec 09 '25 12:12

Randy


2 Answers

admin_enqueue_scripts() only fires in your back-end admin area (/wp-admin/) - https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts

wp_enqueue_scripts() is used to properly enqueue scripts in front-end (https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts)

So if your want load stuff in front-end wp_enqueue_scripts() is the way to go.

Cheers

like image 90
FrancescoCarlucci Avatar answered Dec 13 '25 11:12

FrancescoCarlucci


add_action( 'admin_enqueue_scripts', 'your_function_name' ); this is use for the backend side work.

add_action( 'wp_enqueue_scripts', 'your_function_name' ); this is use for front-end side work.

like image 41
Pankaj Kanani Avatar answered Dec 13 '25 11:12

Pankaj Kanani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!