Created
May 30, 2018 18:00
-
-
Save yankiara/a011f401bf59d3bf08e8d07127985a0f to your computer and use it in GitHub Desktop.
Add javascript to WordPress
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 | |
// Add inline javascript before </head> | |
add_action( 'wp_head', 'header_inline_script' ); | |
function header_inline_script() { | |
?> | |
<script> | |
</script> | |
<?php | |
} | |
// Add inline javascript before </body> | |
add_action( 'wp_footer', 'footer_inline_script' ); | |
function footer_inline_script() { | |
?> | |
<script> | |
</script> | |
<?php | |
} | |
// Add script load before </head> | |
add_action( 'wp_enqueue_scripts', 'header_script_load' ); | |
function header_script_load() { | |
wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/custom-scripts', array( 'jquery' ) ); | |
} | |
// Add script load before </body> | |
add_action( 'wp_enqueue_scripts', 'footer_script_load' ); | |
function footer_script_load() { | |
wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/custom-scripts', array( 'jquery' ), true ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment