4

I want to enqueue the stylesheet in functions.php, but it's not loading. What can be problem in my code?

function my_theme_sty() {
    wp_enqueue_style( 'bootstrap', get_template_directory_uri().'/assets/css/bootstrap.css');
}
add_action( 'admin_enqueue_s', 'my_theme_sty' );
2
  • 2
    There is no admin_enqueue_s hook in WordPress.
    – Max Yudin
    Commented Aug 19, 2018 at 9:09
  • Thanku sir now it working ,i was forget to use the hook.. Commented Aug 19, 2018 at 10:37

2 Answers 2

4

Your function should be:

function my_theme_sty() {
    wp_enqueue_style( 'bootstrap', get_template_directory_uri().'/assets/css/bootstrap.css');
}
add_action( 'wp_enqueue_scripts', 'my_theme_sty' );
0
6

There are two useful action hooks for registering / enqueuing external scripts & styles in WordPress:

1. wp_enqueue_scripts:

wp_enqueue_scripts is the proper action hook to use when enqueuing scripts & styles for the front end.

So if you want to add the CSS file on the frontend of the site, then your CODE will be like:

function my_theme_sty() {
    wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.css' );
}
add_action( 'wp_enqueue_scripts', 'my_theme_sty' );

2. admin_enqueue_scripts:

On the other hand, admin_enqueue_scripts is the proper action hook to use when enqueuing scripts & styles for the admin panel.

So if you want to add the CSS file on the admin panel of the site, then your CODE will be like:

function my_theme_sty() {
    wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.css' );
}
add_action( 'admin_enqueue_scripts', 'my_theme_sty' );

Not the answer you're looking for? Browse other questions tagged or ask your own question.