0

here is my functions.php code to enqueue the scripts and styles:

// Add scripts and stylesheets
function first_afro_theme_scripts() {
    wp_deregister_script( 'jquery' ); // deregisters the default WordPress jQuery  
    wp_enqueue_style( 'first-theme-bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', array(), '3.3.5' );
    wp_enqueue_style( 'first-theme-blog', get_template_directory_uri() . '/assets/css/first-theme-blog.css', array(), '3.3.6');
    wp_enqueue_script( 'first-theme-bootstrap-script', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js', array( 'jquery' ), '3.3.5', true );
}

add_action( 'wp_enqueue_scripts', 'first_afro_theme_scripts' );

In the header.php file i have added,

But but when i go to view page source i dont see any of these styles and scripts. I made sure the path are correct.

in my plugins folder, it is a little different. here is the code to enqueue the function:

// Enqueue the custom JavaScript file
function newsletter_afro_enqueue_scripts() {
    // Enqueue jQuery
    wp_enqueue_script( 'jquery', plugin_dir_url( __FILE__ ) . 'includes/assets/js/jquery-3.6.0.js', array(), '3.6.0', true );
    
    // Enqueue the custom CSS file
    wp_enqueue_style( 'newsletter-style', plugin_dir_url( __FILE__ ) . 'includes/assets/css/style.css', array(), '1.0.0', 'all' );
    
    // Enqueue the custom JavaScript file
    wp_enqueue_script( 'newsletter-script', plugin_dir_url( __FILE__ ) . 'includes/assets/js/newsletter-script.js', array( 'jquery' ), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'newsletter_afro_enqueue_scripts' ); 

on view page source, i see the newsletter-style-css but not the script. the scripts files are not working. what am i doing wrong?

I have checked my code many many times. I have checked the path to the files and confirm it is correct. I have looked up on tutorials to see what i am doing wrong i still can't. I have cleared my cache.

sinke
  • 11
  • 1

1 Answers1

0

The script files are being instructed to print in the footer, which is dependent on the wp_footer() function/hook and the wp_print_footer_scripts action hook. Check that your footer.php has wp_footer (action or function) or the wp_print_footer_scripts action.

You can also remove the last parameter from wp_enqueue_script() (true), and that should print the scripts in the header.

Caleb
  • 1,058
  • 1
  • 7
  • 18
  • Hello @celeb. Thank you for your respond. i actually have wp_footer() in footer.php. But I can't find the script files. I see all the styles(CSS) files not the js fies – sinke Jun 14 '23 at 07:48
  • @celeb thanks alot. I actually checked and i had removed the hook because I did not want to be seeing the admin navbar – sinke Jun 14 '23 at 09:44