I'm developing a theme that uses a Twitter Tweets custom widget (Not coded by me). There are several widget areas within the theme and if I try and include the Twitter widget in say the sidebar and the footer at the same time I get this error;

Fatal error: Cannot redeclare echo_tweets_js() (previously declared in..... on line..... 

This is the section of offending code;

function echo_tweets_js() {
        global $pt_twitter_username, $pt_twitter_postcount;
        echo pt_twitter_js($pt_twitter_username, $pt_twitter_postcount);

    add_action('wp_footer', 'echo_tweets_js', 9999);

Is there a way I can make it work if a user decides they want it in 2 places at the same time?

1 Answer 1


Just... call the function again - you only need to include it once!

include './path/to/lib.php';

echo_tweet_js(); // a little tweeting here


echo_tweet_js(); // and a little tweeting over here!
  • That didn't seem to work, I keep getting the same error... Functions are my downfall when it comes to Wordpress, especially widget functions so I could perhaps be doing something wrong Jul 26, 2012 at 12:59
  • 1
    Somewhere in the execution of the script, that function is getting included more than once - find the original, & then remove all others. Jul 26, 2012 at 13:43
  • To make @TheDeadMedic comment a little more clear: There's an include/require somewhere, that should be an include_once/require_once.
    – kaiser
    Jul 26, 2012 at 14:21
  • @kasier Not a huge fan of *_once, but regardless, would be a lot more elegant to simply remove the redundant includes. Jul 26, 2012 at 14:54
  • That doesn't work either, in the functions.php file there's and include_once for another file which contains the twitter widget (Which doesn't have an include or require within it). I have uploaded the entire Twitter widget code here - jsfiddle.net/wXZzh/1 if that helps anyway Jul 26, 2012 at 19:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.