Skip to content

Instantly share code, notes, and snippets.

@yankiara
Created May 30, 2018 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yankiara/a011f401bf59d3bf08e8d07127985a0f to your computer and use it in GitHub Desktop.
Save yankiara/a011f401bf59d3bf08e8d07127985a0f to your computer and use it in GitHub Desktop.
Add javascript to WordPress
<?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