Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample code to add Facebook Messenger as a sharing button to Scriptless Social Sharing.
<?php
add_filter( 'kses_allowed_protocols', 'prefix_allow_messenger' );
/**
* Add Facebook Messenger to the list of allowed URL protocols in WordPress.
*
* @param $protocols
*
* @return array
*/
function prefix_allow_sms( $protocols ) {
$protocols[] = 'fb-messenger';
return $protocols;
}
add_filter( 'scriptlesssocialsharing_messenger_url', 'prefix_add_fb_messenger', 10, 3 );
/**
* Add SMS to settings/allowed sharing buttons
*
* @param $url
* @param $button
* @param $attributes
*
* @return mixed
*/
function prefix_add_fb_messenger( $url, $button, $attributes ) {
$app_id = ''; // enter your fb app ID here
if ( ! $app_id ) {
return $url;
}
$url = add_query_arg(
array(
'link' => $attributes['permalink'],
'app_id' => $app_id,
),
'fb-messenger://share/'
);
return $url;
}
add_filter( 'scriptlesssocialsharing_networks', 'prefix_scriptless_networks' );
/**
* Add FB Messenger to settings/allowed sharing buttons
*
* @param $networks
*
* @return mixed
*/
function prefix_scriptless_networks( $networks ) {
$networks['messenger'] = array(
'name' => 'messenger',
'label' => __( 'Facebook Messenger', 'scriptless-social-sharing' ),
'icon' => 'f39f',
'color' => '#333', // change this to whatever color you want the button to be
);
return $networks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment