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' );

closed as off-topic by Max Yudin, Jacob Peattie, TheDeadMedic, fuxia Aug 23 '18 at 23:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?" – Jacob Peattie, TheDeadMedic, fuxia
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    There is no admin_enqueue_s hook in WordPress. – Max Yudin Aug 19 '18 at 9:09
  • Thanku sir now it working ,i was forget to use the hook.. – Tahridabbas Aug 19 '18 at 10:37
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' );
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.