No matter what I try I can’t seem to get the code snippets to work that will display the number of followers of Twitter.
I tried various ones as the Plugin I’m using is not showing the Twitter number at all, so I need to look for alternatives.
When I tried this snippet, for example, I got the following error message:
http://pastebin.com/iif9g35a
Anybody any idea what’s going wrong here?
I think it’s strange that the “Suscribers to text” plugin doesn’t display the number of followres to begin with – otherwise I wouldn’t have to look for alternatives.
Ouch, that snippet is ancient (I am kinda its author, more precisely adapted to twitter from other snippet). I would strongly consider using some newer solution.
I had later made newer and written from scratch version, try it http://www.rarst.net/script/twitter-counts-wordpress/
Two issues:
fopen()
wrappers, which may be disabled by your hostYou should probably be using
wp_remote_get()
instead offile_get_contents()
. I would also recommend caching the result, rather than storing it as a DB option.But, let’s start with the basics. I’m going to assume that the
preg_match()
part of the WPBeginner code works, and re-wrap it in a more-flexible function.Try putting this in
functions.php
(change$user = 'wpbeginner'
to your own username):Then, wherever you want to output the string, put this in your template file:
(Note that you can get the follower count for any user, by calling
mytheme_get_twitter_follower_count( 'username' );
.)EDIT
From your error message:
mytheme_get_twitter_widget_follower_count()
function call?mytheme_get_twitter_widget_follower_count()
function?If the file is in your theme folder, instead of using
include
, try get_template_part.get_template_part( 'twitter.php' );
The snippet likely works, you’ve just not implemented it correctly.
Where did you save the code from the first code section in that example? where are you
including
the code from?basically, the error is that the path to the file is not correct, it can’t find the
twitter.php
file you’re trying to include.EDIT –
if the twitter.php file is in the root of your theme directory, try including it like this: