0

I'm working on a custom wordpress theme. The js file is in wp-content/theme/custom-theme/js/bootstrap.min.js. I'm not able to load this on page while I can load the custom CSS file. My code is:

function test_styles(){

    /* add style */
    wp_enqueue_style('custom',get_template_directory_uri().'/style.css');

    }

    add_action('wp_enqueue_scripts', 'test_styles');


function test_scripts(){

     /* add script */
    wp_enqueue_script('bootstrap-js',get_template_directory_uri().'/js/bootstrap.min.js', array('jquery'), true);  

    }

    add_action('wp_enqueue_scripts', 'test_scripts')

The functions are in php tags and in functions.php file. Thanks in advance. Help please.

  • 1
    You've verified that no script tag is inserted in source? Does your theme call wp_footer()? – Milo Mar 17 '16 at 18:42
  • Yes, in footer.php. It calls wp_footer(); – beginner Mar 17 '16 at 20:10
  • To be clear, your CSS is loaded but the JS is not? – jdm2112 Mar 17 '16 at 20:26
1

Using your code as-is enqueue works.

Although your arguments are a little off. The true you are supplying to load script in footer (I presume) is actually getting fed into a version argument. So if you are looking for it in the footer with this code it is de-facto loading in the header.

  • Yes - was just about to recommend adding a version argument to fill out the set and ensure the true boolean was read for footer. Well put Rarst. – jdm2112 Mar 17 '16 at 20:28
  • Okay, I get it. But even after this: function test_scripts(){ /* add script */ wp_enqueue_script('bootstrap-js',get_template_directory_uri().'/js/bootstrap.min.js', array('jquery'), false, true); } add_action('wp_enqueue_scripts', 'test_scripts') – beginner Mar 18 '16 at 17:22
  • but even after this according to: wp_enqueue_script ( string $handle, string|bool $src = false, array $deps = array(), string|bool $ver = false, bool $in_footer = false ) which is given on - [link]developer.wordpress.org/reference/functions/wp_enqueue_script/…. It's not loading. – beginner Mar 18 '16 at 17:29
  • As I said simply copy/pasting your code into my dev install works. If you have a problem it's not with this part of it. – Rarst Mar 18 '16 at 21:44

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.