I am using this code from another answer
add_action( 'dynamic_sidebar', 'wpse_96681_hr' );
function wpse_96681_hr( $widget ) {
static $counter = 0;
// right sidebar in Twenty Ten. Adjust to your needs.
if ( 'sidebar' === key( $GLOBALS['wp_registered_sidebars'] ) )
print '<h1>THIS IS SIDEBAR 1</h1>';
if ( 0 !== $counter && 0 === $counter % 1 )
print '<hr><h1>test</h1>';
$counter += 1;
}
The problem is that it can't detect the sidebar correctly key( $GLOBALS['wp_registered_sidebars'] )
always outputs footer-1
that is the last widget area my theme (genesis framework) registers. But it should actually output sidebar
(inside that primary sidebar at least) because that is where I am seeing the test output when I remove the 2 lines.
I could use the before-
and after-widget-area
hooks to add the action there and remove it later but I would prefer a non framework specific version of this code that works everywhere. Any Ideas? Is this code just not working under genesis (my guess) or outdated? Maybe another solution to detect on what widget area the loop is currently on?
// edit: Strange thing (not really) is that this is executed on admin, I see the code there, no problem I can deal with that later, and actually use it to test it and changed the check to === and now its positive on the primary and secondary sidebar for whatever reason. I not get it.
On the frontend however "this is sidebar 1" is not displayed at all. Hate shit like this.