0

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

<?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 ase dynamic_sidebar('Madurai-Right') is working well, any idea? what is wrong with my code ?

1

try to make a simpler code: change

$side_bar= "'$city-Right'";

to

$side_bar= $city . '-Right';

you have extra ' in $side_bar, the way you've done would give you 'Madurai-Right' but you need Madurai-Right, this way

dynamic_sidebar($side_bar)

would be like writing

dynamic_sidebar("'Madurai-Right'")

while you only need

dynamic_sidebar("Madurai-Right")

besides, always avoid variable substitution, concatenation is always more secure.

  • @s_ha_dum i've updated the answer – Jacer Omri Aug 10 '13 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.