0

I'm a bit new to WordPress so please forgive me if is a duplicate question. I created new theme with simple file structure:

functions.php
footer.php
header.php
index.php
style.css
js/

I'm trying to use only custom scripts that i define here:

function mytheme_enqueue_scripts() {
    wp_register_script('underscore', get_template_directory_uri().'/js/underscore.js', array(), null, false);
    wp_register_script('backbone-core', get_template_directory_uri().'/js/backbone.js', array('underscore'), null, false);
    wp_register_script('backbone-app', get_template_directory_uri().'/js/app.js', array('backbone-core'), null, false);
    wp_enqueue_script('underscore');
    wp_enqueue_script('backbone-core');
    wp_enqueue_script('backbone-app');
}
add_action('wp_enqueue_scripts', 'mytheme_enqueue_scripts');

In my index.php i have only get_header() and get_footer() methods and header.php and footer.php have almost only wp_head() and wp_footer() methods accoprdingly, e.g:

<!DOCTYPE html>
<html <?php language_attributes(); ?> ng-app="myapp">
<head>
    <title>My Backbone.js Theme</title>
    <style>body{background-color: lightgreen}</style>
    <?php wp_head();?>
</head>
<body>

But, when I turn my theme on I get bunch of scripts that I don't need, and don't get those I've declared in functions.php except app.js. No Backbone or Underscore are loaded. It would be great if you tell me where am wrong. Thanks

1
  • 1
    The handle underscore is a used for the Underscore script within the WP core, so when you have tried to register a script with the same handle I expect it's been ignored. In turn, you then enqueue underscore which, I suspect, has dependencies and thus they will be enqueued also. – David Gard Mar 10 '15 at 11:20
1

Your code does seem ok, so it is hard to guess why are you not getting expected result. One thing to note is that WordPress ships with its own copies of Backbone and Underscore, it is considered a good practice to use its copies in such case.

The scripts you don't "need" are likely coming from core and/or plugins you have installed. Which probably have their own opinion on what they need to work.

So in the end one strange part is why are you not getting some of scripts you enqueue.

3
  • Thank you, Rarst! I think I should use blank WP install, without plugins or themes, and then install necessary plugins – John Keel Mar 10 '15 at 11:02
  • And may I ask another question that is not really about this topic but still very important to me. If I want to make my backbone template know about some widgets that i need to show - should i use those WordPress [[]] braces or no? I mean if I have a slider, I need to pass some data and some flags for me to know how to style it. How it can be done in the proper way? Thank you – John Keel Mar 10 '15 at 11:38
  • @JohnKeel that would be better off as new question, I hadn't worked with Backbone in WP context. – Rarst Mar 10 '15 at 11:39

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.