Deprecated: Creation of dynamic property SyntaxHighlighter::$brush_names is deprecated in /web/htdocs/www.barattalo.it/home/wp-content/plugins/syntaxhighlighter/syntaxhighlighter.php on line 248

Deprecated: Creation of dynamic property SyntaxHighlighter::$specialchars is deprecated in /web/htdocs/www.barattalo.it/home/wp-content/plugins/syntaxhighlighter/syntaxhighlighter.php on line 326
Get Google Plus Follower count from PHP in Wordpress

Get Google Plus Follower count from PHP in WordPress

I’ve found a similar function to retrieve the number of followers of a Google Plus page, inside WordPress, but it…

Maggio 7, 2014


I’ve found a similar function to retrieve the number of followers of a Google Plus page, inside WordPress, but it didn’t work. There was an error in the preg_match function, probably because the html code of Google Plus has changed. So, here is my new fixed version, which parse Google Plus pages and doesn’t use any allowed API:
Put this function in your functions.php theme file and retrieve google plus followers count wherever you like in your theme’s files.

function getGplusFollowers($url){
	$count = get_transient('gplus_count');
	if ($count !== false) return $count;
	$count = 0;
	$data = file_get_contents($url);
	if (is_wp_error($data)) {
		return '!';
	} else {
		if (preg_match("#([0-9,\.]*)</span>(\s+)?follower#Uis", $data, $matches)) {
			$results =  preg_replace("/[,\.]/", '', $matches[1]);
		}
		if ( isset ( $results ) && !empty ( $results ) ) {
			$count = $results;
		}
	}
	set_transient('gplus_count', $count, 60*60*48); // 72 hour cache
	return $count;
}

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Recommended

Top Social Stories plugin and widget for WordPress

Just released a plugin for WordPress that can be used to track your posts on Facebook, Twitter and Google+. When…

Novembre 3, 2013

Social buttons: the fastest way for WordPress, without plugins

NOTE: the code in this post is written for WordPress but you can easily translate it in any language. You’re here…

Settembre 15, 2015

Optimize WordPress, a long list of tips

In the above image you can see your WordPress before reading this post, and after the optimizations you will make…

WP Gutenberg notes

Collection of notes and thoughts on Wordpress Gutenberg blocks development.

Gennaio 9, 2023

Optimizing LCP, Largest Contentful Paint result

Notes about Core Web Vitals optimization challenge

Gennaio 4, 2023

Test page for Bright Links plugin

To test the plugin hover your mouse to a link, or tap the link on mobile device.

Dicembre 4, 2022