Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Correct way to enqueue scripts and style in WordPress
<?php
/**
* Register Styles and Scripts
*/
add_action( 'wp_enqueue_scripts', 'ft_scripts_styles' );
function ft_scripts_styles() {
if ( !is_admin() ) {
// Use local copy & not Google CDN for jQuery in local development
if ( ! WP_LOCAL_SERVER ) {
// Google CDN jQuery
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js', array(), '1.7.1', true );
}
// Kill l10n
wp_deregister_script( 'l10n' );
wp_register_script( 'driver', plugins_url( 'driver.js', __FILE__ ), array( 'jquery' ), '0.1', true );
wp_register_style( 'twitter-bootstrap', 'https://raw.github.com/twitter/bootstrap/master/bootstrap.min.css', array(), '1.4' );
wp_register_style( 'main', plugins_url( 'style.css', __FILE__ ), array(), '0.1' );
wp_enqueue_script( 'driver' );
wp_enqueue_style( 'main' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.