Header Injection


#1

How to inject a script into the glober header. I entered few lines in the header.php, which is not working. Please help


#2

Hi, proper way to enqueue script is from functions.php file (theme folder root). You can read more about it on WP.org.

If you open Intro theme functions.php file, find comented line `/**

  • Enqueue scripts and styles.
    */` and place yours after (you will see lot of wp_enqueue_script lines)

Better way would be this:

function add_custom_dimi_scripts() {
	wp_register_script('dimi_custom_jquery', get_template_directory_uri() . '/js/custom.js', array('jquery'), '1.0', true);
	wp_enqueue_script('dimi_custom_jquery');
}

It is just an example of custom.js script which is jQuery dependent. In this example custom.js script is located in theme folder > js > custom.js (so you must save your script there).

Of course consider using child theme for modifications of this kind.


#3

I would like to inject below code. How can i make it? Thanks!


<script src="//load.sumome.com/" data-sumo-site-id="c5eac674a593cc813fd70bc5220724f2132e79e954050471d5e825aa20581be2" async="async"></script>

#4

Oh, for that. It should work by adding code to header.php just above wp_head();

Also you can use some plugin like Insert Headers and Footers.