Skip to content

Instantly share code, notes, and snippets.

@colegeissinger
Last active December 18, 2015 11:38
Show Gist options
  • Save colegeissinger/5776745 to your computer and use it in GitHub Desktop.
Save colegeissinger/5776745 to your computer and use it in GitHub Desktop.
Add JS to homepage of WordPress site
// Save your JavaScript to a file like mobile-redirect.js and we'll assume it's in a directory called "js" in your themes root
// Now use this code to add to your WordPress theme in your functions.php
function cg_add_custom_js_script() {
// more info on this function here http://codex.wordpress.org/Function_Reference/wp_enqueue_script
if ( is_home() || is_front_page() )
wp_enqueue_script( 'custom-js-id', get_stylesheet_directory_uri() . '/js/mobile-redirect.js' );
}
add_action( 'wp_enqueue_scripts', 'cg_add_custom_js_script' );
@colegeissinger
Copy link
Author

Actually... let's make this better.

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