Last active
December 18, 2015 11:38
-
-
Save colegeissinger/5776745 to your computer and use it in GitHub Desktop.
Add JS to homepage of WordPress site
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
// 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually... let's make this better.