0

My client wants to add the live chat script code from here website, but he wants it to put on the specific menu /contact-menu/ I'm not how I could implement it. please let me know any thoughts about this I'm not really familiar in javascript

this is the javascript for live chat:

<script type="text/javascript">!function(e,t,n){function a(){var e=t.getElementsByTagName("script")[0],n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://beacon-v2.helpscout.net",e.parentNode.insertBefore(n,e)}if(e.Beacon=n=function(t,n,a){e.Beacon.readyQueue.push({method:t,options:n,data:a})},n.readyQueue=[],"complete"===t.readyState)return a();e.attachEvent?e.attachEvent("onload",a):e.addEventListener("load",a,!1)}(window,document,window.Beacon||function(){});</script>
<script type="text/javascript">window.Beacon('init', '602b66a1-948e-493f-b0dd-c2828b2eb860')</script>

Thanks

  • is /contact-menu/ a page? – majick Oct 10 '19 at 4:56
  • I've moved to draft the /contact-us/ page, as for now I only put custom menu which contacts us. are they any code to put the contact menu? – Jake Sampan Oct 11 '19 at 5:54
0

Use add_action to add a function to the wp_footer hook, and then inside the function you can check if you are on a specific page before outputting the script.

eg. the Help Scout scripts on the /contact-us/ page:

add_action('wp_footer', 'maybe_add_javascript');
function maybe_add_javascript() {
    if (!is_page('contact-us')) {return;}
    ?>
    <script type="text/javascript">!function(e,t,n){function a(){var e=t.getElementsByTagName("script")[0],n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://beacon-v2.helpscout.net",e.parentNode.insertBefore(n,e)}if(e.Beacon=n=function(t,n,a){e.Beacon.readyQueue.push({method:t,options:n,data:a})},n.readyQueue=[],"complete"===t.readyState)return a();e.attachEvent?e.attachEvent("onload",a):e.addEventListener("load",a,!1)}(window,document,window.Beacon||function(){});</script>
    <script type="text/javascript">window.Beacon('init', '602b66a1-948e-493f-b0dd-c2828b2eb860')</script>
    <?php
} 
  • Hi Majick, thank you! is this code will work? should I just copy the entire code and put on the function.php? I don't really know much on the javascript thing, it would be a great help to me if you walk me through on how I could implement step by step please? – Jake Sampan Oct 15 '19 at 23:59
  • as of now, I only add a custom menu and put an # sign, I named it "contact-us" is the code you gave will work for on custom menu? – Jake Sampan Oct 16 '19 at 0:04
  • I put the code and but it won't work, I'd created the contact us page but still wont work:( – Jake Sampan Oct 16 '19 at 0:14
  • yes you can add this to your child theme functions.php or as a file in /wp-content/mu-plugins/ ... this is based on the contact us page being a standard page with page slug of contact-us, the script will be added to the footer of that page, you can check if it is happening in the page source. if you add the page to the custom menu then when you click on it it will take you to the page where the script loads. beyond that, what the script does and how it works I have no knowledge of. – majick Oct 16 '19 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.