So You Only Want Intercom Chat On Certain Pages In WordPress? Here’s How!

So I had a client want to use Intercom. Great! So I went to Intercom and signed up for an account, then went to our WordPress instance and downloaded the Intercom for WordPress plugin. Everybody wins! Until…I get the requirement after the fact that the client does not want the chat pop up on every page…but only on certain pages. However, the out of the box Intercom for WordPress plugin is only built to be supported for all pages and not some. What to do…what to do…let’s figure it out.

First, login into your WordPress (.org version) as an admin and uninstall the Intercom for WordPress plugin. Next install the Head, Footer and Post Injections Plugin:

Once installed, go to the Head, Footer and Post Injections plugin settings and insert the following script injection into the Desktop and Mobile (Check the Mobile checkbox) BEFORE THE CLOSING TAG (FOOTER). 

<script>
var ref1= window.location.pathname;
var search1 = "/pagepath1/";
var search2 = "/pagepath2/"; 
if (ref1.indexOf(search1) > -1 || ref1.indexOf(search2) > -1)
  window.intercomSettings = {
    app_id: "YourIntercomID"
  };
</script>
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/nna8fbly';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>

Save the plugin settings. This JavaScript will check on the specified page paths and only execute turning on Intercom for the specific page paths. Hope this helps!

Advertisements

Questions? Comments?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s