Skip to content

Instantly share code, notes, and snippets.

@justincarroll
Last active December 18, 2015 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justincarroll/5814115 to your computer and use it in GitHub Desktop.
Save justincarroll/5814115 to your computer and use it in GitHub Desktop.
This is an ongoing list of my most-used WordPress snippets for functions.php files. Take the meat, spit out the bones! The eating references in these descriptions are mounting.
<?php
/* Updates jQuery manually */
function update_jquery() {
if (!is_admin()) {
wp_deregister_script("jquery");
wp_register_script("jquery", "http://code.jquery.com/jquery.js", false, "11.11.1");
wp_enqueue_script("jquery");
}
}
add_action("init", "update_jquery");
/* Adds custom scripts to the page */
function my_scripts() {
if ( !is_admin() ) {
global $wp_styles;
wp_enqueue_style("bootstrap", "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css");
wp_enqueue_style("font-awesome", "http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css");
wp_enqueue_style("style", get_template_directory_uri() . "/style.css");
wp_enqueue_script("bootstrap", "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js", array("jquery"));
wp_enqueue_script("html5shiv", "https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js");
$wp_styles->add_data("html5shiv", "conditional", "lt IE 9");
wp_enqueue_script("respond", "https://oss.maxcdn.com/respond/1.4.2/respond.min.js");
$wp_styles->add_data("respond", "conditional", "lt IE 9");
wp_enqueue_script("script", get_template_directory_uri() ."/js/default.js", array("jquery"));
}
}
add_action("wp_enqueue_scripts", "my_scripts");
?>
@vdobrev
Copy link

vdobrev commented Dec 20, 2013

for some reason the conditionals don't seem to work for me in WP 3.8
scripts just get included in head without the conditional tags ;(

@olavxxx
Copy link

olavxxx commented Nov 23, 2015

wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );

2 pointers:

  1. Maybe you should put "what you can" in the footer?
  2. Maybe adding versions for enqueues? (because of caching issues if you upgrade script versions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment