Adding inline script or style to WordPress in head element

In your theme’s functions.php:

function inline_scripts() {
    ?>
	<script>console.log('test here');</script>
	<?php
}
// Add hook for admin <head></head>
add_action( 'admin_head', 'inline_scripts' );
// Add hook for front-end <head></head>
add_action( 'wp_head', 'inline_scripts' );

Leave a Reply

Your email address will not be published. Required fields are marked *