Exclude Certain Pages – where to put script
-
I saw the script to exclude certain pages, I’m just wondering where do I place this code exactly?
And how do I find the Page # of the pages I want to exclude?
Thanks in advance!
-
You can put that code in the
functions.phpfile which is inside your theme. Make sure it goes after the opening<?php.You can see the ID number of a page by editing the page, and the URL will be something like
wp-admin.php/post.php?post=1234where 1234 is the ID number of the page.Cool thanks Simon!
I have another Q – just wondering about registering new users from WP to Intercom via the plugin.
Does the plugin hookup with the main WP database, so that whenever a new user is created, the user’s details are sent to Intercom?
Because I have a site where I only want certain users registered in Intercom, not every user.
Can you see a way around this with the plugin?
Thanks again.
It only send users’ details to Intercom when they visit the front-end of your site, not at the moment they register.
If you want to exclude certain users from being tracked, you could do it by role (see the first example in the FAQ), or you could do it by user IDs. Put the code below in your
functions.phpfile, and replace the IDs in the array with the ones you want to exclude.add_filter( 'll_intercom_output_snippet', 'exclude_users_from_intercom' ); function exclude_users_from_intercom( $show ) { $user_id = get_current_user_id(); $exclude = array( 5, 6, 123 ); if ( in_array( $user_id, $exclude ) ) return false; return true; }So if they visit a page that has the script, then the plugin sends their data to Intercom, correct?
Then, if I exclude the code from certain pages, this group of users that sees these pages won’t get registered in Intercom, even though they’re registered on my WP site, right?
Using an example, I have Users A and Users B.
Users A get access to the whole site.
Users B only get access to Page X.
If I exclude the Intercom script using the code you gave me originally from Page X, will Users B be registered in Intercom?
Yes, that’s correct, user data is only sent when a user visits a page (although you might want to test it by setting up a test user account to make sure).
WICKED – will run a test.
Thanks so much Simon!
Actually one more question – how do I modify the script for excluding multiple pages?
This should do the trick. Replace the IDs in the array with the ones you want to exclude:
add_filter( 'll_intercom_output_snippet', 'no_intercom_on_some_pages' ); function no_intercom_on_some_pages( $show ) { $exclude = array( 10, 13, 678 ); if ( is_page( $exclude ) ) return false; return true; }Hmm, something funny happened.
So I installed the plugin and was about to add the code to the functions.php, but I see that the plugin is not working in that the chat icon doesn’t appear on my front end at all.
I’ve added all the required details in the backend but still, the code is not showing up when I click “View Source” in Chrome.
Any idea?
Are you logged in as an administrator? It does not show to admin users, only editors or below.
THAT’S THE TICKET!
Thanks so much Simon.
Everything works including the code you gave me to exclude pages.
Awesome stuff – your help is greatly appreciated!
Happy to help π
Hey there, the snippet above didn’t work for me, any thoughts?
Hi Keith – sorry, I’m no longer supporting or maintaining this plugin (see the announcement here). There is now an official Intercom plugin available at https://wordpress.org/plugins/intercom
The topic ‘Exclude Certain Pages – where to put script’ is closed to new replies.