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 currently have a widget that needs to be manually displayed on the front page. The rest of the pages it shows up in the widget sidebar, (this is accomplished with 'Widget Logic') but on the front page I need it to display in a different area. I tried using the_widget() but the issue is that it doesn't display any of the saved data for the widget. How can I manually display the widget and get my saved data for the widget to display?

SOLUTION: This is the code that ended up solving my problem. Basically you can retrieve widget data using get_option. I did a var_dump of the result and found the array that I wanted and fed it back into the_widget function. I guess the only issue here is if a user ever deletes the widget and remakes it, the array key will most likely change. But it works for now.

if(function_exists('the_widget')) {
$instance = get_option( 'widget_backspikewidget' ); 
the_widget('BackSpikeWidget', $instance[2]);
}
share|improve this question
1  
While this is not impossible (just will take some messing with global variables to accurately get data out) - why not just add dedicated sidebar for front page? –  Rarst Mar 23 '12 at 14:00
    
I already have a sidebar on the front page but I don't want the widget to appear in that particular place. I could create another widget area but then I'd be creating a new instance of the widget which means existing data will not carry over. –  greatwitenorth Mar 23 '12 at 14:18
    
If this is solved, submit your answer as a solution and mark it solved. –  m0r7if3r Mar 23 '12 at 15:14
    
I can't because I don't have enough points to respond to my answer –  greatwitenorth Mar 23 '12 at 15:30
add comment

1 Answer 1

I like the answer you found, but I thought I'd tack on another.

You could create another sidebar area that's only displayed on the front page, and then use the "Duplicate Widget" plugin to maintain two instances of a single plugin.

It has slightly higher overhead, but becomes much easier to maintain for someone who doesn't code.

share|improve this answer
add 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.