Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/473716773968031744
Better formatting
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

Is it possible to return a widget instance into a variable or array? I'm thinking something along the lines of $widget['title']$widget['title'], $widget['content']$widget['content'] etc.

I have tried inspecting the global $wp_registered_widgetsglobal $wp_registered_widgets variable but this only seems to contain information relevant to rendering the widget, not the widget content itself. I am also able to retrieve the rendered widget by using

ob_start(); 
dynamic_sidebar('widgetarea'); 
$sidebar = ob_get_contents();    
ob_end_clean();

Which I suppose I could then parse into a series of dom nodes with jQuery parseHTML method, however this seems like a very messy way to go about it and I wonder if anyone could suggest a more elegant way?

Is it possible to return a widget instance into a variable or array? I'm thinking something along the lines of $widget['title'], $widget['content'] etc.

I have tried inspecting the global $wp_registered_widgets variable but this only seems to contain information relevant to rendering the widget, not the widget content itself. I am also able to retrieve the rendered widget by using

ob_start(); 
dynamic_sidebar('widgetarea'); 
$sidebar = ob_get_contents();    
ob_end_clean();

Which I suppose I could then parse into a series of dom nodes with jQuery parseHTML method, however this seems like a very messy way to go about it and I wonder if anyone could suggest a more elegant way?

Is it possible to return a widget instance into a variable or array? I'm thinking something along the lines of $widget['title'], $widget['content'] etc.

I have tried inspecting the global $wp_registered_widgets variable but this only seems to contain information relevant to rendering the widget, not the widget content itself. I am also able to retrieve the rendered widget by using

ob_start(); 
dynamic_sidebar('widgetarea'); 
$sidebar = ob_get_contents();    
ob_end_clean();

Which I suppose I could then parse into a series of dom nodes with jQuery parseHTML method, however this seems like a very messy way to go about it and I wonder if anyone could suggest a more elegant way?

Source Link

Create variable from widget instance

Is it possible to return a widget instance into a variable or array? I'm thinking something along the lines of $widget['title'], $widget['content'] etc.

I have tried inspecting the global $wp_registered_widgets variable but this only seems to contain information relevant to rendering the widget, not the widget content itself. I am also able to retrieve the rendered widget by using

ob_start(); 
dynamic_sidebar('widgetarea'); 
$sidebar = ob_get_contents();    
ob_end_clean();

Which I suppose I could then parse into a series of dom nodes with jQuery parseHTML method, however this seems like a very messy way to go about it and I wonder if anyone could suggest a more elegant way?