WordPress dynamic widget by location?

i need to show the widget based on user location , for a testing purpose i have created the by using following code

if( function_exists( 'register_sidebar' ) )
register_sidebar( array( 'name'=>'Madurai-Right',
'before_widget' => '<div class="widget relativ">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) ); 

and getting the widget like below

Read More
<?php $city="Madurai";  echo $side_bar= "'$city-Right'"; ?>
    <?php if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar($side_bar) ) :?>
    &nbsp;
    <?php endif; ?>

Here city is the location, so based on the location i am getting the sidebar as dynamic_sidebar($side_bar) it doesn’t working

But if i use without the variable inside the dynamic_sidebar('Madurai-Right') is working well, any idea? what is wrong with my code ?

Related posts

Leave a Reply

2 comments

  1. This is correct for hardcoded side-bar=”city-Right”

    <?php $city="Madurai";  echo "side_bar='" . $city . "-Right'"; ?>
        <?php if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar($side_bar) ) :?>
        &nbsp;
    <?php endif; ?>