WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 2 months ago

#13169 closed enhancement (maybelater)

Return Dynamic Sidebars with get_dynamic_sidebar

Reported by: w3prodigy Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Widgets Keywords:
Focuses: 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;
}

Change History (3)

comment:1 w3prodigy4 years ago

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;
}

comment:2 avryl9 months ago

  • Component changed from General to Widgets

comment:3 ocean902 months ago

  • Milestone Future Release deleted
  • Resolution set to maybelater
  • Status changed from new to closed

This is the first request for a get variant of dynamic_sidebar(). Currently I don't see how core or a theme could benefit of it.

Marked as maybelater.

Note: See TracTickets for help on using tickets.