Site Header Custom Code Addition

I need to add the following script in the following place (site header) per the vendors guideline, please advise how I can do:

<!doctype html>
<html lang="en">
<head>
<title>Your website</title>
<link rel="stylesheet" href="css/styles.css"/>
**// Vidpulse code goes here**
</head>
<body>
Content
</body></html>

// Vidpulse code:

<script data-cfasync= "false" >
(function(v,i,d,p,u){d[v]=d[v]||function(){ (d[v].q=d[v].q||[["time",0,+new Date()]]).push(arguments)}; u=p.getElementsByTagName(i)[0];p=p.createElement(i); p.async=1; p.src="https://s.vidpulse.com/all/vp.js"; u.parentNode.insertBefore(p,u)})("vidpulse","script",window,document); vidpulse("create", "vp_QjeB74");
</script>

I tried the following which loaded fine in the functions.php in the child pro theme however script is not being activated:

function my_vidpulse_script() { ?>

 add_action( 'wp_head', 'my_vidpulse_script', 999 );
<script data-cfasync="false">

(function(v,i,d,p,u){d[v]=d[v]||function(){
    (d[v].q=d[v].q||[["time",0,+new Date()]]).push(arguments)};
    u=p.getElementsByTagName(i)[0];p=p.createElement(i);
    p.async=1; p.src="https://s.vidpulse.com/all/vp.js";
    u.parentNode.insertBefore(p,u)})("vidpulse","script",window,document);
    vidpulse("create", "vp_QjeB74");

</script> <?php }

Hi There @affiliatepitch

Thanks for writing in! The simplest way would be to use a 3rd party party plugin (https://wordpress.org/plugins/insert-headers-and-footers/)

Then you can add your js code in Scripts in Header section.

Or else, you need to update your code by following the code below.

add_action('wp_head','custom_javascript');
function custom_javascript () { ?>

<!-- Replace this with your javascript code -->

<?php }

Hope that helps

Thank you will try both options and will let you know what works.

You are most welcome. :slight_smile:

Hi Support,

Just to let you know both options suggested works very well.

Thanks again, please also address my secure note.

Kind regards

Hey there,

Glad it works now, and I changed your username as requested.

Thanks!

Hi Support, if I wanted to use multiple scripts using the functions.php, how would I use this?

For example :

// Script 1:

add_action('wp_head','custom_javascript1');
function custom_javascript1 () { ?>

<!-- Replace this with your javascript code -->

<?php }

// Script 2:

add_action('wp_head','custom_javascript2');
function custom_javascript2 () { ?>

<!-- Replace this with your javascript code -->

<?php }

Thanks

Hi @hootycreative,

You don’t need multiple of it, it can be something like this

add_action('wp_head','custom_javascript');
function custom_javascript () { ?>

<!-- Replace this with your javascript code 1 -->

<!-- Replace this with your javascript code 2 -->

<!-- Replace this with your javascript code 3 and so on -->

<?php }

Thanks!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.