Include third party javascript on home page

Hi,

I have added following url in script tag as src and with all required options in footer.
src=“https://mylivechat.com/chatinline.aspx?hccid=xxxxxxxx” async=“async” defer=“defer” type=“text/javascript” data-cfasync=“false”

Other than home page, all pages have footer so I can see chat bubble in all pages except home page. Home page is a full page slider(revolution slider). I want to display same chat bubble in home page too. So how can I achieve that? Where should I add that script for home page?

Thank You!

Hi There,

Please try adding the following code under functions.php file locates in your child theme instead:

add_action( 'wp_footer', 'x_print_footer_script' );
function x_print_footer_script(){
    ?>
    <scrip src="https://mylivechat.com/chatinline.aspx?hccid=xxxxxxxx" async="async" defer="defer" type="text/javascript" data-cfasync="false"></scrip>
    <?php
}

Hope it helps :slight_smile:

Thanks Thai! but I do not want to create child theme. Is there any option in admin only?

Hey There,

Since you do not want a child theme, please install a 3rd party plugin “Insert Headers and Footers” (https://wordpress.org/plugins/insert-headers-and-footers/). This will give you an option to insert the code in the footer without having to use a child theme.

Hope this helps.

Good to know there is such plugin. I tried this plugin but it is not working. I checked that script has been included or not and I found that it doesn’t include that script. I feel like it is because of full page revolution slider on home page.

Any thoughts on that?

Thanks!

Hello There,

You only need this line in the footer:

<scrip src="https://mylivechat.com/chatinline.aspx?hccid=xxxxxxxx" async="async" defer="defer" type="text/javascript" data-cfasync="false"></scrip>

You might have inserted the wrong code. After making the changes, you will have to clear your plugin cache first before testing the site.

Please let us know how it goes.

After cache clear I could see that script in footer but somehow I was not able to see that chat bubble in footer. So from my mylivechat account I copied another code and added in footer section of that new plugin with script tag(insert-headers-and-footers) and it works like charm :slight_smile:

The new code is as follow:

function add_chatinline(){var hccid=xxxxxxxx;var nt=document.createElement("script");nt.async=true;nt.src="https://mylivechat.com/chatinline.aspx?hccid="+hccid;var ct=document.getElementsByTagName("script")[0];ct.parentNode.insertBefore(nt,ct);}
add_chatinline(); 

Thank you so much for all your help and support!

Glad to hear it’s working. :slight_smile:

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