Try to include your inline script at the bottom of your snipper.js
file, and then enqueue it using wp_enqueue_scripts()
:
function my_chat_script() {
wp_enqueue_script( 'chat-js', 'URL OF SNIPPER HERE', false );
}
add_action( 'wp_enqueue_scripts', 'my_chat_script' );
This is the proper way to include scripts in your WordPress using functions.php
file.
However, if you insist on adding them separately, you can use wp_add_inline_script()
:
function chat_script() {
wp_enqueue_script( 'my-chat-script', 'SNIPPER URL HERE', array(), '1.0' );
wp_add_inline_script( 'my-chat-script', 'SERVICE_PATTERN_CHAT_CONFIG = {appId: '0ef0636b4c36497b866322a096926049', clientId: 'WebChat',apiUrl: 'https://poc.3d2b.ccaas.becloudsolutions.com:9443/clientweb/api/v1',tenantUrl: '3d2b.com',width: 300,chatPath: ''};' );
}
add_action( 'wp_enqueue_scripts', 'chat_script' );
This will output your snippet and inline script separately.