Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thewheat
Last active October 11, 2017 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewheat/4adc1f122552a3b3b3733ac2a2f7948d to your computer and use it in GitHub Desktop.
Save thewheat/4adc1f122552a3b3b3733ac2a2f7948d to your computer and use it in GitHub Desktop.
Creating a child theme for customisation of Intercom's Wordpress plugin https://wordpress.org/plugins/intercom/ / https://github.com/intercom/intercom-wordpress

Details

Installation

  • Save style.css and function.php into a folder (e.g. intercom-child)
  • Modify style.css to specify the name of the existing theme you have to base this of off
  • Modify function.php with any customisation options you wish to have
  • Upload folder to your Wordpress instance: https://codex.wordpress.org/Using_Themes#Adding_New_Themes
  • Select and activate this child theme in your Wordpress
<?php
function my_theme_enqueue_styles() {
$parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
// Code below from: https://gist.github.com/thewheat/887c6009c8058e8140a0f8c086e3b841
// If you wish to manually install Intercom without any plugin: https://gist.github.com/JackGJenkins/039bdfce9c82cdc2eeb09df42d5079f3
////////////////////////////////////////////////////////////////////////////////////////////////////
// Customise functionality of the default Intercom Wordpress plugin
// https://github.com/intercom/intercom-wordpress
////////////////////////////////////////////////////////////////////////////////////////////////////
// This code can be added to a plugin or a theme
// Simplest install would be in your theme's function.php file
////////////////////////////////////////////////////////////////////////////////////////////////////
// customise the current Intercom script
// - add custom attributes https://docs.intercom.io/configuring-intercom/send-custom-user-attributes-to-intercom
// - add custom activator https://docs.intercom.io/configuring-Intercom/in-app-messenger#custom-style
function customise_intercom(){
// $current_user = wp_get_current_user(); // get current Wordpress user if needed
echo "\n".'<script>';
// ensure this is defined, i.e. don't break if Intercom plugin not installed
echo "\n".'window.intercomSettings = window.intercomSettings || {};';
// specify custom attributes
// echo "\n".'window.intercomSettings["test_string"] = "123";';
// widget activator old messenger
// echo "\n".'window.intercomSettings.widget = {"activator":"#idOfActivatorElement"};';
///////////////////////////////////////////////////////////////////////////////////////////
// new messenger customizations
// https://docs.intercom.com/configure-intercom-for-your-product-or-site/customize-the-intercom-messenger/customize-the-intercom-messenger-technical
///////////////////////////////////////////////////////////////////////////////////////////
// use a customer element as a launcher
// echo "\n".'window.intercomSettings["custom_launcher_selector"] = "#idOfActivatorElement";';
// hide the messenger
echo "\n".'window.intercomSettings["hide_default_launcher"] = false;';
echo "\n".'</script>'."\n";
}
// priority 20 ensures it loads after Intercom plugin which users the default value of 10
// https://developer.wordpress.org/reference/functions/add_action/
// https://github.com/intercom/intercom-wordpress/blob/master/bootstrap.php
add_action('wp_footer', 'customise_intercom',20);
////////////////////////////////////////////////////////////////////////////////////////////////////
// add Intercom to admin dashboard i.e. /wp-admin/ interface - 1
add_action('admin_footer', 'add_intercom_snippet');
add_action('admin_footer', 'customise_intercom');
// add Intercom to admin dashboard i.e. /wp-admin/ interface - 0
////////////////////////////////////////////////////////////////////////////////////////////////////
/*
Theme Name: Intercom Child Theme
Template: twentysixteen
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment