0

So I'm trying to link in a javascript file the right way, by using this:

--functions.php--
function custom_scripts() {
    wp_register_script('myscript','/backdrop.js',array('jquery'));
    wp_enqueue_script('myscript'); 
    console.log("test - inside custom_scripts"); 
}
add_action( 'wp_print_scripts', 'custom_scripts');

I don't see the console logs in the chrome console window, and I'm not sure if I should see them or not. However I see that one of my files cannot be found: /backdrop.js?ver=3.5.1. The directory is correct but the ?ver=3.5.1 obviously doesn't match up. Since I'm manually registering the script in a custom functions.php, why does it still do this?

1
  • where is your script exactly? in your theme directory, or the root of your domain?
    – Milo
    Commented Apr 24, 2013 at 1:45

1 Answer 1

1

console.log() is a JavaScript function. You cannot use it in PHP. Add that to your JavaScripts.

The version parameter should not affect the file access. But you can remove that parameter and see if it works then. If it does, your server configuration needs further inspection, because it should also work with the version.

1
  • Oh lol, that's what you get when you are learning 2 languages simultaneously >_> And wow, that did the trick. thank you! Commented Apr 24, 2013 at 2:23

Your Answer

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

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