Reputation: 423
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?
Upvotes: 0
Views: 1548
Reputation: 2799
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' );
Upvotes: 0
Reputation: 411
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' );
Upvotes: 1