Skip to content

Instantly share code, notes, and snippets.

@ai2ik
Created December 28, 2018 18:16
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 ai2ik/2807103661e1cdd32e1f9d31b5f07485 to your computer and use it in GitHub Desktop.
Save ai2ik/2807103661e1cdd32e1f9d31b5f07485 to your computer and use it in GitHub Desktop.
To manually add script to the head of a WordPress site you can use the wp_head action by using one of the the following function examples in function.php If using the echo function you will need to use double quotes around scripts single quotes to keep from breaking the function.
<?php
/**
* add script to head with wrapping php
*/
function addtohead_cf() {
?>
<script></script>
<?php
}
add_action('wp_head', 'addtohead_cf');
/**
* add script to head using echo
*/
function addtohead_cf() {
echo "<script></script>";
}
add_action( 'wp_head', 'addtohead_cf' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment