Forums
Home / Fixing WordPress / How to add plugin code to header html using function
(@fetchbranding)
9 years ago
How can I add this code to my header html using a function? I need to add this to a childtheme.
<!–Start of Zopim Live Chat Script–> <script type=”text/javascript”> window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s= d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set. _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute(“charset”,”utf-8″); $.src=”//v2.zopim.com/?2viiMwgRkUnV0tYLYPgg6qcXqEgN0Gtk”;z.t=+new Date;$. type=”text/javascript”;e.parentNode.insertBefore($,e)})(document,”script”); </script> <!–End of Zopim Live Chat Script–>
(@jaycbrf)
Save the script in a js folder in child theme then add this to child theme’s functions.php:
function custom_scripts() { // Loads theme JavaScript file. wp_enqueue_script('customjs', get_template_directory_uri() . '/js/custom.js', false ); } add_action('wp_enqueue_scripts', 'custom_scripts');
(@wpyogi)
See:
https://codex.wordpress.org/Using_Javascript
BTW, are you using this plugin?
https://wordpress.org/plugins/zopim-live-chat/
Best to ask on the support for that plugin here:
https://wordpress.org/support/plugin/zopim-live-chat