Skip to content

Static Social Sharing

Ben Gillbanks edited this page Jul 28, 2020 · 7 revisions

Add social sharing buttons that use static sharing urls.

This:

  1. Keeps your site fast by not including slow javascript from social networks.
  2. Keeps your site private by not adding 3rd party tracking scripts.

Filter: toolbelt_social_sharing_post_types

By default the social sharing will display on blog posts and, if the module is enabled, portfolio posts. You can change this with a filter.

Display social sharing on all single post types

function my_social_sharing_post_types() {
	return '';
}
add_filter( 'toolbelt_social_sharing_post_types', 'my_social_sharing_post_types' );

Display social sharing on posts and pages

function my_social_sharing_post_types() {
	return array( 'post', 'page' );
}
add_filter( 'toolbelt_social_sharing_post_types', 'my_social_sharing_post_types' );

Display on your own post type

function my_social_sharing_post_types( $types ) {
        $types[] = 'my-post-type';
	return $types;
}
add_filter( 'toolbelt_social_sharing_post_types', 'my_social_sharing_post_types' );

Filter: toolbelt_display_social_sharing

This filter runs after the post types have been filtered out. You can use this to hide the sharing options on specific posts, or older content, or whatever you can think of.

function my_display_social_sharing() {
    // Hide for post id 4.
    if ( 4 === (int) get_the_ID() ) {
        return false;
    }
    // Show for all other posts.
    return true;
}
add_filter( 'toolbelt_display_social_sharing', 'my_display_social_sharing' );

Filter: toolbelt_social_networks

Filter the social networks that are displayed. This is a 1 dimensional array.

The following example changes the social networks so that only Twitter, Facebook, and Email buttons are displayed.

function my_social_networks( $networks ) {
    return array(
        'twitter',
        'facebook',
        'email'
    );
}
add_filter( 'toolbelt_social_networks', 'my_social_networks' );

Hide Buttons

The easiest way to hide social networks is to use some custom css added to the 'additional css' section of the customizer.

The following example will hide the Pinterest link.

.toolbelt-social-share .toolbelt_pinterest { display: none; }

Note: If you are comfortable with programming then using the new toolbelt_social_networks filter is the better option.

Networks

By default the plugin adds support for Facebook, Twitter, LinkedIn, Whatsapp, Pinterest, Pocket, Wallabag, Reddit, and Email.

Clone this wiki locally