0

I can't link the external JavaScript file to my WordPress theme through the plugin. All I found is this way to attach a JavaScript file:

function theme_name_scripts() {
    wp_register_script('script-name-faizan-test', 'http://vjs.zencdn.net/4.12/video.js');
    wp_enqueue_script('script-name-faizan-test');
}

add_action('wp_enqueue_scripts', 'theme_name_scripts');

What am I doing wrong?

1
  • where have you put it? how do you know it's not working? Commented Sep 4, 2015 at 14:45

2 Answers 2

1

According to the WP Codex, the example gives extra parameters:

<?php wp_register_script( $handle, $src, $deps, $ver, $in_footer ); ?>

So:

function child_add_scripts() {
    wp_register_script(
        'google-analytics',
        'http://google.com/analytics/script.js',
        false,
        '1.0',
        true
    );

    wp_enqueue_script( 'google-analytics' );
Sign up to request clarification or add additional context in comments.

Comments

0

Check this link out:

Note that your relative path may be different.

function wptuts_scripts_basic()
  {
  // Register the script like this for a plugin:
  wp_register_script( 'custom-script', plugins_url( 'http://vjs.zencdn.net/4.12/video.js', __FILE__ ) );
  // or
  // Register the script like this for a theme:
  wp_register_script( 'custom-script', get_template_directory_uri() . 'http://vjs.zencdn.net/4.12/video.js' ); 

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.