Reputation: 23
I have the following code:
function register_scripts(){
wp_register_style( 'new_style', plugins_url('/css/style.css', __FILE__));
wp_register_script( 'google-maps-api', 'http://maps.google.com/maps/api/js?sensor=false' );
}
add_action('wp_enqueue_scripts', 'register_scripts');
But it is not working, can anyone see what I've done wrong?
Upvotes: 2
Views: 2209
Reputation: 15979
Like in comment - You have registered them, but not enqueued...
function regiqueue_scripts(){
wp_register_style( 'new_style', plugins_url('/css/style.css', __FILE__));
wp_register_script( 'google-maps-api', 'http://maps.google.com/maps/api/js?sensor=false' );
wp_enqueue_style( 'new_style' ); // or use just enqueue without register .. but not the other way around
wp_enqueue_script( 'google-maps-api' );
}
add_action('wp_enqueue_scripts', 'regiqueue_scripts');
You see - registering the scripts just makes them available for use, but it will not enqueue until you tell it to do so. the function wp_enqueue_xx()
- when all parameters filled CAN work without wp_register_xx()
- but not the other way around.
Always use both as it allows more control over where and when to use the script.
Upvotes: 5