Change the theme location for share buttons

You can set Shared Counts to automatically insert the buttons before and/or after the content of your page. The hook or filter used will depend upon your theme (see the code here):

  1. If you are using a Genesis theme:
    • “Before” uses the genesis_entry_header hook with a priority of 13
    • “After” uses the genesis_entry_footer hook with a priority of 8
  2. If your theme supports the Theme Hook Alliance:
    • “Before” uses the tha_entry_top hook with a priority of 13
    • “After” uses the tha_entry_bottom hook with a priority of 8
  3. If you are using any other theme:
    1. “Before” uses the the_content filter with a priority of 8
    2. “After” uses the the_content filter with a priority of 12

Change location

You can modify these locations using the shared_counts_theme_locations filter.

Let’s say you have added a hook to your theme for your post intro:

do_action( 'be_post_intro' );

You could tell Shared Counts to use this hook for the “Before” location like so:

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

/**
 * Move Shared Counts
 * @see https://sharedcountsplugin.com/2019/03/27/change-the-theme-location-for-share-buttons/
 *
 * @param array $locations
 * @return array
 */
function be_shared_counts_location( $locations ) {
	$locations['before']['hook'] = 'be_post_intro';
	$locations['before']['filter'] = false;
	return $locations;
}
add_filter( 'shared_counts_theme_locations', 'be_shared_counts_location' );

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.