I’m struggling to understand how to enqueue an external js file with some widget code within WordPress. For example: there is a Frontapp chatbot that has to have the following code placed into the end of the tag with my theme:
<script src="https://chat-assets.frontapp.com/v1/chat.bundle.js"></script>
<script>
window.FrontChat('init', {chatId: '0xxxx', useDefaultLauncher: true});
</script>
How would I enqueue this since there’s both an external link & snippet of Js?
2
Answers
You can use
wp_enqueue_script
for external scripts as well aswp_add_inline_script
for inline scripts.In your case that would be.
Those lines should appear in
wp_enqueue_scripts
hook like all other enqueued scripts. If you want it at the footer, addtrue
to the footer parameter. So all in all:I hope this will solve your problem.