Last active
August 17, 2020 19:53
-
-
Save nevilpaul/a9e58458bebf284735f0dee59b99142c to your computer and use it in GitHub Desktop.
This function assists you in intergrating intercom to your wordpress page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*@author nevilpaul.. | |
*@mail: info@netdevelops.com | |
*@date published:12/07/2018 | |
*/ | |
<?php | |
// copy the code from here in the function.php file and disable the intercom plugin replace 'APP-ID' with the actual id of your app | |
global $wp; | |
function intercom_script_footer(){ | |
if ( is_user_logged_in() ) { | |
$current_user = wp_get_current_user(); ?> | |
<script> | |
/* Show intercom widget */ | |
window.intercomSettings = { | |
app_id: 'APP_ID', | |
email: '<?php echo $current_user->user_email; ?>', | |
user_id: '<?php echo $current_user->ID; ?>', | |
name: '<?php echo $current_user->display_name; ?>', | |
created_at: <?php echo strtotime(get_userdata($current_user->ID)->user_registered); ?> | |
}; | |
<?php } else { ?> | |
<script> | |
//********* remove this script code if you want only intercom to be visible to user************************* | |
/* Show intercom widget */ | |
window.intercomSettings = { | |
app_id: 'APP_ID' | |
}; | |
//************************** end of remove ***************************************************************** | |
<?php } ?> | |
/*Show intercom widget */ | |
(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/APP_ID';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> | |
<?php } | |
/*script included when user is logged in*/ | |
function is_page_to_include(){ | |
intercom_script_footer(); | |
}; | |
// To add intercom to the front end of your wordpress site: | |
add_action('wp_footer', 'is_page_to_include'); | |
//To add intercom to the admin area of your wordpress site: | |
add_action( 'admin_enqueue_scripts', 'is_page_to_include' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment