Add .js to Child Theme

I need to add a chat widget to my site using some .js

Here is the instructions I have received: I changed the ip address slightly.

Step #1 - Define the jquery.js and css files within the head of the customers web site. If the customer site is already using jquery only include the link for ChatStyle.css.

                    <script src="http://173.164.162.xxx/ISWeb/Chat/jquery.js"></script>
                    <script src="http://173.164.162.xxx/ISWeb/Chat/jquery-ui.js"></script>
                    <link href="http://173.164.162.xxx/ISWeb/Chat/jquery-ui.css" rel="stylesheet" />
                    <link href="ChatStyle.css" rel="stylesheet" />"
Step #2 - Include the Chatjs.js script file before the tag
                    <script src="http://173.164.162.129/ISWeb/Chat/ChatDemo/Chatjs.js"></script>

#3- I can add the chat widget to the page using raw code element.

I need a bit of assistance as to what code to add to my child theme to make this work?

Thank you.

Hi there,

You will need to use the wp_head action to do so. Please kindly read the article below for more information:

https://theme.co/apex/forum/t/customizations-actions-and-filters-in-x/208

As mentioned in the article you need to add a PHP code to your functions.php file of the Child Theme like this:

function third_party_tracking_code() { ?>

  <script>
    // Third party tracking code.
  </script>

<?php {

add_action( 'wp_head', 'third_party_tracking_code' );

You do not need to add the jQuery library as it is already available on the theme and WordPress.

Thank you.

Thank you for the reply but when I try to implement this code in the functions.php of my child theme it breaks my site. Did you test this code?

Thank you.

Hello There,

Sorry there was a typography error. Please use this code instead:

function third_party_tracking_code() { ?>

  <script>
    // Third party tracking code.
  </script>

<?php }
add_action( 'wp_head', 'third_party_tracking_code' );

The error was the opening and closing curly brackets.

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