0

I am new to bootstrap and WordPress and trying to put together a simple page. So, it doesn't surprise me that I'm running into dependency problems adding and registering scripts from both the header and footer.

Is there anything obvious here that I'm missing?

<?php 
function wpbootstrap_scripts_with_jquery() { // Register the script like this for a theme: wp_register_script( 'custom-script', get_template_directory_uri() . 'js/bootstrap.js', array( 'jquery' ) );

// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . 'js/jquery.tweet.js', array( 'jquery' ) );


// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . 'js/clock.js', array( 'jquery' ) );


// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . 'js/soon.js', array( 'jquery' ) );
//footer scripts

// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . 'js/dat.gui.min.js', array( 'jquery' ) );


// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . 'js/fss.js', array( 'jquery' ) );


// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . 'js/bgCustom.js', array( 'jquery' ) );


// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'custom-script' );
} add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );

?>
3
  • all of your scripts have the same handle name: custom-script, each call to wp_register_script overwrites the previous one. give them unique handles.
    – Milo
    Nov 15, 2013 at 18:34
  • Please edit your question do describe what you expect to happen that's not happening, or what's happening unexpectedly. Just saying that you're having "dependency problems" doesn't adequately describe the problem to allow us to help answer it. Nov 15, 2013 at 18:48
  • Please follow up on the questions you asked, it's an important part of the process on WPSE - see What should I do when someone answers my question? and Why is voting important? for a deeper insight. Thank you! Nov 27, 2013 at 22:01

1 Answer 1

3

As mentioned on the wp_register_script() codex page the handle:

Should be unique as it is used as a handle for later use with wp_enqueue_script().

You are using the same handle for all your scripts, which won't work.

Besides that, if those scripts are depending on bootstrap, you have to at least register bootstrap before and add it as dependency to the custom scripts registration. Or, enqueue it before enqueuing the custom scripts with wp_enqueue_script(), which also has an dependencies parameter. Read more about the usage at the linked pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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