Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created September 11, 2019 16:31
Show Gist options
  • Save robincornett/b4d68b30401bda1bb1f7c8d7e9d65caf to your computer and use it in GitHub Desktop.
Save robincornett/b4d68b30401bda1bb1f7c8d7e9d65caf to your computer and use it in GitHub Desktop.
Sample code to add the Print Friendly service as a scriptless sharing button
<?php
add_filter( 'scriptlesssocialsharing_networks', 'rgc_scriptless_networks' );
/**
* Add Print Friendly to settings/allowed sharing buttons
*
* @param $networks
*
* @return mixed
*/
function rgc_scriptless_networks( $networks ) {
$networks['print'] = array(
'name' => 'print',
'label' => __( 'Print', 'scriptless-social-sharing' ),
'icon' => 'f02f', // the glyph for the Font Awesome icon
'color' => '#121212', // change this to whatever color you want the button to be
);
return $networks;
}
add_filter( 'scriptlesssocialsharing_print_url', 'rgc_add_print_friendly_url', 10, 3 );
/**
* Add the print friendly URL to the new print button.
*
* @param string $url
* @param string $button_name
* @param array $attributes
* @return string
*/
function rgc_add_print_friendly_url( $url, $button_name, $attributes ) {
$query_args = array(
'url' => $attributes['permalink'],
);
return add_query_arg(
$query_args,
'https://www.printfriendly.com/print'
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment