How to add code to the header in WordPress

WordPress has a hook that lets us add arbitrary HTML code to the <header> tag of a website. Several plugins can be found that accomplish this, but it’s so easy to do that a plugin is often overkill.

Here’s how you can execute an arbitrary PHP function using the wp_head hook:

// write some text as part of the header 
function writeSomeText () { 
    echo 'Hello from my new header function.'; 
add_action('wp_head', 'writeSomeText');

This example inserts some text into the <header> portion of the website. HTML tags can simply be written using echo, including double quotes.

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at and