Forked from ashfame/Correct-way-to-enqueue-scripts-and-style-in-WordPress.php
Created
May 8, 2023 13:05
-
-
Save slopesweb/e4b2eeef491dce2a8ecb6fbe41ee51a0 to your computer and use it in GitHub Desktop.
Correct way to enqueue scripts and style in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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