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 Answer 1

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.

1
  • @s_ha_dum i've updated the answer Commented Aug 10, 2013 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.