WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#41070 new defect (bug)

register_sidebar and dynamic_sidebar inconsistency

Reported by: derkjanspeelman Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Widgets Keywords:
Focuses: Cc:

Description

Let's register a sidebar in functions.php and use digits for the value of the id key.

<?php
register_sidebar( array(
        'id'   => 'test123',
        // or 'id' => '123',
        // or 'id' => 123,
        'name' => 'test - Mega Menu',
) );

After that, the Widget is showing up at Appearance > Widgets. But when we'd like to retrieve this widget using the dynamic_sidebar function, it won't work:

<?php
var_dump(dynamic_sidebar( 'test123' ));
var_dump(dynamic_sidebar( '123' ));
var_dump(dynamic_sidebar( 123 ));

All var_dumps will return bool(true)

Change History (2)

#1 @mdifelice
4 years ago

Hi @derkjanspeelman, I've tried your code in my environment and I did not get the same output. Could you please give us more information: the sidebar has widgets? your theme has other sidebars? etc.

The dynamic_sidebar() function does return true when there is at least one widget loaded in it. So it is weird it does also print the widget itself when calling it.

#2 @mdgl
4 years ago

See also #37893. Widget functions are all over the place with regard to numeric sidebar identifiers.

Note: See TracTickets for help on using tickets.