I am creating a theme for Wordpress, but the wp_enqueue_scripts does not work. The code that is in functions.php is:

function scripts_and_styles() {

  if ( ! is_admin() ) {
      wp_enqueue_script( 'jQuery' );
      wp_register_style( 'style.css',get_template_directory_uri().'/style.css' );
      wp_enqueue_style( 'style.css' );
      wp_register_style( 'bootstrap.min.css','https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
      wp_enqueue_style( 'bootstrap.min.css' );

add_action('wp_enqueue_scripts', 'scripts_and_styles');

Other information that may help identify what is happening :

  • When I insert echo 'Oi!'; appears Oi! in index.php, as expected;
  • I have to enter <?php do_action('wp_enqueue_scripts') ?> in header.php, and from what I understood this would not be necessary;
  • When I call var_dump in wp_enqueue_script( 'jQuery' ); and in the others wp_enqueue_script() is 'printed' NULL in index.php;
  • Anything that uses jQuery work on my theme ( I believe that because I can not call it);
  • I'm using XAMPP.

I appreciate the help ! Sorry for my english , I 'm not fluent .

The solution: I was not calling wp_head() and wp_footer()

  • Does your theme have calls to wp_head and wp_footer? Sep 12 '16 at 13:39
  • @AndyMacaulay-Brook Yes, it has these calls. I rummaged through various websites and forums , and I have no idea why this happens . I do exactly what is said.
    – Rafaelfdib
    Sep 12 '16 at 13:55
  • @AndyMacaulay-Brook Sorry, I'm dumb, I'm using <?php get_header() ?>!
    – Rafaelfdib
    Sep 12 '16 at 14:01
  • That loads your header. Then last thing before your closing HTML head tag you also need wp_head() which is where the action fires. Sep 12 '16 at 14:05
  • @AndyMacaulay-Brook Thank you very much!
    – Rafaelfdib
    Sep 12 '16 at 14:11

If do_action works, then the problem should be you are not calling wp_head() and wp_footer() in your header.php and footer.php respectively.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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