0

I am trying to enqueue a couple of js files using something like this code:

function scripts_function() 
{
    wp_register_script('mapbox', 'http://api.tiles.mapbox.com/mapbox.js/v0.6.7/mapbox.js');
    wp_enqueue_script('mapbox');

    wp_register_script('myscript', plugins_url( 'my-js-file.js' , __FILE__ ));
    wp_enqueue_script('myscript');
}
add_action('wp_enqueue_scripts', 'scripts_function');

And this works fine, as long as i use the "twentytwelve" theme wich i used while creating this plugin I' working on. But now I want to implement it on the HTML5 blank theme wich i was thinking about using as a startpoint for my theme, but then this just stops working, doesnt enqueue my my-js-file.js, but the mapbox script hosted on cdnjs is included just fine.

If i inspect the code in the browser, i can see that where the script tag for my js-file should be there is just a script tag with a src attribute without a value:

<script type="text/javascript" src></script>

If i do print_r(plugins_url( 'my-js-file.js' , __FILE__ ));, I get a path to my js file wich I can paste into the browser and that works fine.

What is going on here?

1

I'm not sure but it might have something to do with the html5blank_protocol_relative() function used by HTML5 Blank Theme. You could try removing the filters at L# 382 & 383 of the functions.php file.

// Protocol relative URLs for enqueued scripts
add_filter( 'script_loader_src', 'html5blank_protocol_relative' );
// Protocol relative URLs for enqueued styles
add_filter( 'style_loader_src' , 'html5blank_protocol_relative' );

The problem shouldn't be related to the wp_head() call, since the starter theme already has it in place.

  • Yes you are correct, just tried to remove the str_replace() function that replaces http and https with nothing. This seems to be a problem when working locally, it doesn't seem to take the "//localhost....." links to well :) thank you – Millenjo Apr 18 '13 at 11:34
  • @gyo Please use the proper formatting provided by the WYSIWYG editor in your answers. Thanks. – kaiser Apr 18 '13 at 12:24
  • 1
    @kaiser I've changed the bolds to inline-code formatting, if that's what you mean. – gyo Apr 19 '13 at 8:08
  • 1
    @gyo Yes, that was what I meant. I edited it a bit more to show you what's possible. Just click the edit link to see the MarkUp. Hint: There's a help link right to the comment field in which I'm just typing that will show you some basic MarkUp that works inside the comments, answers, questions and even chat. There're as well keyboard shortcuts that might help you. For e.g.: Mark some code and press Ctrl + K and you'll get code formatting. – kaiser Apr 19 '13 at 10:11
  • 1
    @kaiser thanks for the info, I think it's better as you edited. However, if you check my other answers you'll notice that I'm already using formatting. – gyo Apr 19 '13 at 10:21
0

Always have wp_head() just before the closing </head> tag of your theme, or you will break many plugins, which generally use this hook to add elements to <head> such as styles, scripts, and meta tags.

<?php
 wp_head();
?>
  • Well, I'm not using the head hook, I'm using the wp-enqueue-scripts hook just because of the fact that wp_head isn't dependable. – Millenjo Apr 18 '13 at 11:23

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.