Skip to content

Instantly share code, notes, and snippets.

@subrotoice
Last active December 23, 2016 09:48
Show Gist options
  • Save subrotoice/4f4a54cd3b9bce5cacb26871e7cde8a4 to your computer and use it in GitHub Desktop.
Save subrotoice/4f4a54cd3b9bce5cacb26871e7cde8a4 to your computer and use it in GitHub Desktop.
<?php
/**
* Proper way to enqueue scripts and styles
*/
function wpdocs_theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() ); // style.css
wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css',false,'1.1','all');
wp_enqueue_script( 'script-name', 'https://cdnjs.cloudflare.com/ajax/libs/fuelux/3.15.10/js/fuelux.min.js', array(), '1.0.0', false ); // If you used true then it load in_footer, Default: False
wp_enqueue_script('oxfam_js_cookie', 'https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.0/js.cookie.min.js', array(), null, true); // Remove version variable by using null
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
// It just works on template-name.php
wp_register_style( $handle, get_stylesheet_directory_uri().'/relative/path/to/stylesheet.css', array(), '', true );
if ( is_page_template( 'template-name.php' ) ) {
wp_enqueue_style( $handle );
}
// Depedency of script. If 'jquery' and 'jquery-ui' not load then it will not load
function myscripts() {
//get some external script that is needed for this script
wp_enqueue_script('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js');
$script = get_template_directory_uri() . '/library/myscript.js';
wp_register_script('myfirstscript',
$script,
array ('jquery', 'jquery-ui'),
false, false);
//always enqueue the script after registering or nothing will happen
wp_enqueue_script('fullpage-slimscroll');
}
add_action("wp_enqueue_scripts", "myscripts");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment