Last active
December 25, 2015 14:59
-
-
Save bMinaise/6994739 to your computer and use it in GitHub Desktop.
Load Scripts in Wordpress 'the WRITE way'
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 | |
/* | |
* WordPress Sample function and action | |
* for loading scripts in themes | |
*/ | |
add_action( 'wp_enqueue_scripts', 'wptuts_styles_with_the_lot' ); | |
function wptuts_styles_with_the_lot() | |
{ | |
// Register the style like this for a plugin: | |
wp_register_style( 'custom-style', plugins_url( '/css/custom-style.css', __FILE__ ), array(), '20120208', 'all' ); | |
// or | |
// Register the style like this for a theme: | |
wp_register_style( 'custom-style', get_template_directory_uri() . '/css/custom-style.css', array(), '20120208', 'all' ); | |
// For either a plugin or a theme, you can then enqueue the style: | |
wp_enqueue_style( 'custom-style' ); | |
} | |
// Let's hook in our function with the javascript files with the wp_enqueue_scripts hook | |
add_action( 'wp_enqueue_scripts', 'wpcandy_load_javascript_files' ); | |
// Register some javascript files, because we love javascript files. Enqueue a couple as well | |
function wpcandy_load_javascript_files() { | |
wp_register_script( 'info-caroufredsel', get_template_directory_uri() . '/js/jquery.carouFredSel-5.5.0-packed.js', array('jquery'), '5.5.0', true ); | |
wp_register_script( 'info-carousel-instance', get_template_directory_uri() . '/js/info-carousel-instance.js', array('info-caroufredsel'), '1.0', true ); | |
wp_register_script( 'jquery.flexslider', get_template_directory_uri().'/js/jquery.flexslider-min.js', array('jquery'), '1.7', true ); | |
wp_register_script( 'home-page-main-flex-slider', get_template_directory_uri().'/js/home-page-main-flex-slider.js', array('jquery.flexslider'), '1.0', true ); | |
wp_enqueue_script( 'info-carousel-instance' ); | |
if ( is_front_page() ) { | |
wp_enqueue_script('home-page-main-flex-slider'); | |
} | |
} | |
//ANOTHER WAY TO ENQUEUE SCRIPTS | |
function wptuts_scripts_important() | |
{ | |
// Register the script like this for a plugin: | |
wp_register_script( 'custom-script', plugins_url( '/js/custom-script.js', __FILE__ ) ); | |
// or | |
// Register the script like this for a theme: | |
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/custom-script.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_important', 5 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment