Skip to content

Snippet: Add Print Button to Social Share

Important: This is no longer required! The Total theme now includes this option built-in to the theme since version 5.6.0.

The following snippet can be used to add a print button to the theme's social share icons.

/**
 * Add new options for the social share buttons.
 *
 * @link https://total.wpexplorer.com/docs/snippets/add-print-button-to-social-share/
 */
add_filter( 'wpex_get_social_items', function ( $items ) {
	$items['print'] = array(
		'site'       => 'Print',
		'label'      => 'Print',
		'li_class'   => 'custom-print',
		'icon_class' => 'ticon ticon-print',
		'href'       => '#print',
	);
	return $items;
} );

/**
 * Adds javascript for a custom print social share button.
 *
 * @link https://total.wpexplorer.com/docs/snippets/add-print-button-to-social-share/
 */
add_action( 'wp_enqueue_scripts', function() {
	$script = '
	jQuery( document ).ready(function() {
		jQuery( ".wpex-social-share li.custom-print a" ).click( function() {
			window.print();
		} );
	} );';
	wp_add_inline_script( 'jquery', $script );
} );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top