Advertisements

Speeding up Shared Counts

One of the things I most like about Shared Counts is how customizable it is. Previously I’ve shown you how to create custom social sharing buttons for both WhatsApp and Reddit but the customizability doesn’t end there. This guide will show you how to use two of Shared Counts’ filters to further speed up the plugin and reduce the amount of JavaScript and CSS that is loaded on each of your pages and posts.

This guide will once again be making use of the very handy Code Snippets plugin. If you haven’t done so yet, go ahead and install it. Shared Counts is not the only application which can make use of it. I’d generally consider it a must-have plugin and have it installed on all of my many WordPress websites.

Disabling Shared Counts JavaScript

The first step in speeding up Shared Counts is disabling JavaScript (JS). While it will make your whole site faster, it does have a few consequences you might want to consider before doing so.

You will no longer be able to use the Share by Email button as the opening, closing, and submitting of it is handled by JavaScript. Shared Counts will also stop reporting events to Google Analytics, so you won’t be able to see how your visitors interact with your social sharing buttons. Finally, new windows opened by Shared Counts might not have the optimal dimensions.

I can personally live with these restrictions and have thus disabled the Shared Counts JavaScript, as speed is one of my top priorities when designing websites. To do so yourself, create a new snippet in Code Snippets and enter the following line:

add_filter( 'shared_counts_load_js', '__return_false' );

Give your snippet a fitting name, save it, and activate it. Congratulations, you’ve just disabled the Shared Counts JavaScript.

AMP compatibility, a positive side effect

If you are using the official AMP plugin for WordPress, you will notice a positive side effect of disabling JavaScript. Shared Counts should no longer be causing any errors when posts and pages are validated.

Disabling Shared Counts CSS stylesheet

Another way of ensuring that visitors don’t have to download as many assets when trying to view your WordPress website, is by disabling the CSS stylesheet containing the many style options offered by Shared Counts.

Please note that you should only disable the Shared Counts CSS stylesheet if you have already created your own style. If you are using one of the styles offered by Shared Counts (Fancy, Slim, Classic etc.) do not enable this snippet as it will effectively break the plugin.

However, if you are using your style, I highly suggest you add and enable the following snippet, as the CSS stylesheet from Shared Counts will just waste bandwidth and slow down your site:

add_filter( 'shared_counts_load_css', '__return_false' );

About Liam Alexander Colman

Liam Alexander Colman has been working with GeneratePress for over two years and has built countless WordPress websites using it. In his personal setting, Liam maintains six websites. While not a developer, he has created innumerable GeneratePress Elements and is well versed in customizing the theme to his liking. Visit this link for more information and a showcase of his work.

Leave a comment

Advertisements