Cómo inyectar código HTML solo en el head en páginas de inicio y de publicación

The code is Adsense auto ads in the header. Should I then create a conditional statement in javasciprt and rewrite that code to insert the javascript then?