• Resolved layza

    (@layza)


    Hello!

    I’d need to add a chat in wordpress theme. The chat is made in html and javascript.
    I tried to add it on local with twentyseventeen theme installed using this code, and it worked fine.

    ` function add_chat ( ) {
    ?>
    <script type=”text/javascript”>
    SERVICE_PATTERN_CHAT_CONFIG = {
    appId: ‘0ef0636b4c36497b866322a096926049’,
    clientId: ‘WebChat’, /* no need to change this */
    apiUrl: ‘https://poc.3d2b.ccaas.becloudsolutions.com:9443/clientweb/api/v1&#8217;,
    tenantUrl: ‘3d2b.com’,
    width: 300,
    chatPath: ”

    };
    </script>
    <script type=”text/javascript” src=”js/snippet.js”></script>
    <?php
    }

    add_action (‘wp_footer’, ‘add_chat’ );`

    But If I try to do the same thing online with another theme, I didn’t work.

    Any advice?

    Thank you in advance

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Put the script into a js file (or files) and use wp_enqueue_script() to add it to a page.

    Thread Starter layza

    (@layza)

    Hi Steve,

    thank you for your answer.

    I tried to do that, adding this in functions.php

    wp_enqueue_script( 'chat', get_theme_file_uri( '/chat/js/chat.js' ), array(), true );
    add_action( 'wp_enqueue_scripts', 'chat' );

    And this

    <script type="text/javascript" src="js/snippet.js"></script>
    In the header.php right after the <body> tag. It worked on local with twentyseventeen, but it didn’t online with the other theme. Have I done something wrong?

    Thanks

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    in functions.php

    function add_chat_scripts() {
       wp_enqueue_script( 'chat', get_stylesheet_directory_uri() . '/chat/js/chat.js' , array(), true );
       wp_enqueue_script( 'chat-snippet', get_stylesheet_directory_uri() . '/js/snippet.js', array('chat') );
       }
    add_action( 'wp_enqueue_scripts', 'add_chat_scripts' );

    Assuming that you have those scripts in those locations relative to your theme.

    Thread Starter layza

    (@layza)

    Thanks, I tried but it doesn’t work ??

    Thread Starter layza

    (@layza)

    Actually, I can see website homepage, but it gives me this error on any other page:

    Fatal error: Call to undefined function wp_enque_script() in /home/content/n3pnexwpnas02_data01/42/2910242/html/wp-content/themes/thekeynote-v1-07/functions.php on line 123

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I spelled it wrong. enqueue

    Thread Starter layza

    (@layza)

    Ok, thanks a lot. I tried but it still not working on the keynote theme, while is working ok on twentyseventeen. How it can be possible?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I don’t know. You’d have to ask the devs of that theme.

    Thread Starter layza

    (@layza)

    There was an error in the path for js.
    Thank you for your help Steve, much appreciated! Have a nice day ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘ADD chat in WordPress’ is closed to new replies.