Opened 3 years ago
Last modified 3 years ago
#13169 new enhancement
Return Dynamic Sidebars with get_dynamic_sidebar
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Currently there is no available function to return the contents of a dynamic sidebar. The following code enables developers to return and assign the contents of a dynamic sidebar to a variable within their code.
function get_dynamic_sidebar($index = 1)
{
$sidebar_contents = "";
ob_start();
dynamic_sidebar($index);
$sidebar_contents = ob_get_contents();
ob_end_clean();
return $sidebar_contents;
}
Note: See
TracTickets for help on using
tickets.

Thanks to Filosofo for pointing out that we can use ob_get_clean() instead of ob_get_contents() and ob_end_clean(). The use of output buffering is a simple solution until further can be developed.
function get_dynamic_sidebar($index = 1) { $sidebar_contents = ""; ob_start(); dynamic_sidebar($index); $sidebar_contents = ob_get_clean(); return $sidebar_contents; }