Reputation: 179
I want to add some code to the head of each page that loads using a plugin that I build. What is the proper hook for this and the proper way of doing it? Thanks a lot
Upvotes: 4
Views: 2707
Reputation: 1185
For those looking for a sample code, here it is:
add_action( 'wp_head', 'YOUR_SCRIPT_IN_HEAD_FUNCTION' );
function YOUR_SCRIPT_IN_HEAD_FUNCTION() {
echo '<script>
// some code
</script>';
}
Upvotes: 5
Reputation: 547
To add JS code, use the wp_enqueue_script() function - put your call in a function which gets added to the filter 'wp_enqueue_scripts'.
To add HTML, write a function to render whatever code you need and put it onto the wp_head filter. As in add_action('wp_head', 'your_function');
Does that help?
Upvotes: 0