Add a Reddit share button

Shared Counts includes buttons for the most popular social sharing platforms, and you can use the built-in filters to add support for additional services.

The code below adds a Reddit share button. Note that this will not increase the total share count when shared on reddit. This only adds a sharing button. Here’s some information on retrieving share count data from Reddit.

This code snippet goes in a core functionality plugin or Code Snippets.

/**
 * Add Reddit to Shared Count admin Services setting.
 *
 * @see 
 * @param $services array Available services.
 * @return array
 */
function be_shared_counts_reddit_admin_services( $services ) {
	$services['reddit'] = 'Reddit';
	return $services;
}
add_filter( 'shared_counts_admin_services', 'be_shared_counts_reddit_admin_services' );

/**
 * Add Reddit Link to available output.
 * 
 * @see 
 * @param array $link Available link properties.
 * @return array
 */
function be_shared_counts_reddit_link_properties( $link ) {

	if ( 'reddit' === $link['type'] ) {
		$link['link']   = 'https://www.reddit.com/submit?url=' . $link['url'];
		$link['target'] = '_blank';
		$link['icon']   = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512"><path d="M128 320c0-17.673 14.327-32 32-32s32 14.327 32 32c0 17.673-14.327 32-32 32s-32-14.327-32-32zM320 320c0-17.673 14.327-32 32-32s32 14.327 32 32c0 17.673-14.327 32-32 32s-32-14.327-32-32zM321.556 388.389c8.241-6.493 20.188-5.077 26.682 3.166s5.076 20.189-3.167 26.683c-22.948 18.079-57.911 29.762-89.071 29.762s-66.124-11.683-89.072-29.761c-8.243-6.495-9.66-18.441-3.166-26.684 6.495-8.241 18.441-9.659 26.683-3.166 13.211 10.409 39.361 21.611 65.555 21.611s52.344-11.202 65.556-21.611zM512 256c0-35.346-28.654-64-64-64-24.058 0-44.996 13.285-55.926 32.91-32.896-17.997-72.976-29.623-116.64-32.304l38.191-85.763 73.097 21.1c6.576 18.671 24.359 32.057 45.278 32.057 26.51 0 48-21.49 48-48s-21.49-48-48-48c-18.28 0-34.171 10.221-42.277 25.257l-81.453-23.512c-9.112-2.629-18.769 1.861-22.626 10.526l-51.885 116.513c-42.569 2.998-81.631 14.511-113.818 32.118-10.932-19.625-31.883-32.902-55.941-32.902-35.346 0-64 28.654-64 64 0 26.156 15.701 48.627 38.186 58.551-4.035 12.014-6.186 24.552-6.186 37.449 0 88.365 100.288 160 224 160s224-71.635 224-160c0-12.896-2.15-25.431-6.184-37.443 22.485-9.925 38.184-32.401 38.184-58.557zM432 94c9.941 0 18 8.059 18 18s-8.059 18-18 18-18-8.059-18-18 8.059-18 18-18zM32 256c0-17.645 14.355-32 32-32 12.754 0 23.786 7.502 28.923 18.323-16.724 12.683-30.583 27.313-40.833 43.369-11.762-4.735-20.090-16.256-20.090-29.692zM256 474c-102.725 0-186-54.621-186-122s83.275-122 186-122c102.725 0 186 54.621 186 122s-83.275 122-186 122zM459.91 285.692c-10.25-16.056-24.109-30.686-40.833-43.369 5.138-10.821 16.169-18.323 28.923-18.323 17.645 0 32 14.355 32 32 0 13.436-8.328 24.957-20.090 29.692z"></path></svg>';
	}
	
	return $link;
}
add_filter( 'shared_counts_link', 'be_shared_counts_reddit_link_properties' );

Filters used:

Published by Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributor to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.