Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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!
share|improve this answer
    
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 –  Dean Elliott Jul 26 '12 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. –  TheDeadMedic Jul 26 '12 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 '12 at 14:21
    
@kasier Not a huge fan of *_once, but regardless, would be a lot more elegant to simply remove the redundant includes. –  TheDeadMedic Jul 26 '12 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 –  Dean Elliott Jul 26 '12 at 19:01
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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