Include Shared Counts styles when loaded via AJAX

Shared Counts only loads its styles if the share buttons are called in the current page. If you’re loading them via AJAX, they wouldn’t be in place on initial load.

You can resolve this by telling Shared Counts the buttons are loading on the page. Add this to your theme’s functions.php file:

if( function_exists( 'shared_counts' ) ) {
	shared_counts->front->share_link = true;
}Code language: PHP (php)

This will load the styles site-wide. You can add your own conditionals to that to better reflect where you want the styles loaded.

For instance, if you are only loading them via AJAX on single posts, use:

if( function_exists( 'shared_counts' ) && is_single() ) {
	shared_counts->front->share_link = true;
}Code language: PHP (php)

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.