skip to Main Content

Add custom JavaScript to the WordPress Header with functions.php

To add a tiny simple JavaScript, for instance  a test for some jQuery functionality, to your wordpress head int he frontend simply add this to your themes functinos.php.

function my_header_script(){?><script>alert( 'This is a header test' ); </script><?php}add_action( 'wp_head', 'my_header_script' );

You can also add something to the footer

function my_footer_script(){?><script>alert( 'This is a footer test' ); </script><?php}add_action( 'wp_footer', 'my_footer_script' );

Read more:

Back To Top