skip to Main Content

I m adding the following script(zendesk chat widget) on the header.php – in the wordpress website domain.com, in two ways neither works. Chat widget only displayed on all pages if we are loggedin to wordpresss, Otherwise it would be displayed on some inner pages eg: domain.com/some-inner-pages

First script I added looks like this

<script id="ze-snippet" src="https://static.zdassets.com/ekr/snippet.js?key=<key>"> 

</script> 

Then checked domain.com and it didnt work but if i go domain.com/some-inner-pages it would work, also it would work if I login as admin.

The second try was

<script>
  function loadZendeskWidget() {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.id = 'ze-snippet';
      script.async = true;
      script.src = 'https://static.zdassets.com/ekr/snippet.js?key=<key>';
      document.getElementsByTagName('head')[0].appendChild(script);
  };
</script>

<script type="text/javascript">
    loadZendeskWidget(); 
    console.log("test");

</script>

Still the same behavior as the first attempt.

Is there anyway I can debug this or fix this? Thanks for any help

header.php file

<!doctype html>

<html <?php language_attributes(); ?> class="no-js">
<head>

<!-- Meta Tags -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<?php

$options = get_nectar_theme_options();

if ( ! empty( $options['responsive'] ) && $options['responsive'] == 1 ) { ?>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<?php } else { ?>
    <meta name="viewport" content="width=1200" />
<?php } ?>  

<!--Shortcut icon-->
<?php if ( ! empty( $options['favicon'] ) && ! empty( $options['favicon']['url'] ) ) { ?>
    <link rel="shortcut icon" href="<?php echo esc_url( nectar_options_img( $options['favicon'] ) ); ?>" />
<?php }

wp_head();

if ( ! empty( $options['google-analytics'] ) ) {
    echo $options['google-analytics'];}
?>
 <!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-154156568-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-154156568-1');
</script>
<!-- Start of  Zendesk Widget script -->

<script>
  function loadZendeskWidget() {
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.id = 'ze-snippet';
      script.async = true;
      script.src = 'https://static.zdassets.com/ekr/snippet.js?key=XX';
      document.getElementsByTagName('head')[0].appendChild(script);
  };
</script>

<script type="text/javascript">
    loadZendeskWidget(); 
    console.log("test");

</script>
<!--<script id="ze-snippet" src="https://static.zdassets.com/ekr/snippet.js?key=XX"> 

</script> -->
<!-- End of  Zendesk Widget script -->
</head>

<?php

global $post;
global $woocommerce;

$nectar_header_options = nectar_get_header_variables();

?>

<body <?php body_class(); nectar_body_attributes(); ?>>

<?php

nectar_hook_after_body_open();

if ( $nectar_header_options['theme_skin'] == 'material' ) {
    echo '<div class="ocm-effect-wrap"><div class="ocm-effect-wrap-inner">';
}

if ( $nectar_header_options['n_boxed_style'] ) {
    echo '<div id="boxed">';
}

nectar_page_trans_markup();

get_template_part( 'includes/partials/header/secondary-navigation' );

get_template_part( 'includes/partials/header/header-space' );

?>

<div id="header-outer" <?php nectar_header_nav_attributes(); ?>>

    <?php

    if ( empty( $options['theme-skin'] ) || ( ! empty( $options['theme-skin'] ) && $nectar_header_options['theme_skin'] != 'ascend' && $nectar_header_options['header_format'] != 'left-header' ) ) {
        get_template_part( 'includes/header-search' );
    }

    get_template_part( 'includes/partials/header/header-menu' );


    if ( ! empty( $options['enable-cart'] ) && $options['enable-cart'] == '1' && $nectar_header_options['theme_skin'] != 'material' ) {

        if ( $woocommerce ) {
            echo nectar_header_cart_output();
        }
    }

    ?>


</div><!--/header-outer-->

<?php

if ( ! empty( $options['enable-cart'] ) && $options['enable-cart'] == '1' ) {
      get_template_part( 'includes/partials/header/woo-slide-in-cart' );
}

if ( $nectar_header_options['theme_skin'] == 'ascend' || $nectar_header_options['header_format'] == 'left-header' ) {
    if ( $nectar_header_options['header_search'] != 'false' ) {
        get_template_part( 'includes/header-search' ); }
}

if ( $nectar_header_options['mobile_fixed'] != '1' ) {
    get_template_part( 'includes/partials/header/classic-mobile-nav' );
}

?>

<div id="ajax-content-wrap">

<?php
if ( $nectar_header_options['side_widget_area'] == '1' && $nectar_header_options['side_widget_class'] == 'fullscreen' ) {
    echo '<div class="blurred-wrap">';
}

Here’s the screenshots of header

enter image description here

enter image description here

2

Answers


    • Did you try to move the script to the footer?
    • Did you try to include a downloaded/local version of the script with eg.

      wp_enqueue_script( 'script', get_template_directory_uri() .
      '/js/script.js', array ( 'jquery' ), 1.1, true);

      in your
      functions.php to include the script?

    • Did you test different browsers (disable all plugins, incognito mode)?
    • Is any white/blacklisting going on (configuration zendesk) or blocking from external scipt loading?
    • Is the header.php from home the same as sub or is there any chance, that another header.php is loaded?
    Login or Signup to reply.
  1. If you are adding zendesk chat widget then add the embed script in header.php file between the page’s head tags.

    You can paste it either right after the opening <head> tag or right before the closing </head>.

    <!-- Start of  Zendesk Widget script -->
    
    <script id="ze-snippet" src="https://static.zdassets.com/ekr/snippet.js?key=<key>"></script>
    
    <!-- End of  Zendesk Widget script -->
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search