Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I can sucesfully get my dynamic sidebar to work like so:

<div class="sidebar sidebar-first">
    <ul class="widget-area first">
        <?php dynamic_sidebar( 'pop-photos-sidebar' ); ?>
    </ul>
</div>

Now, I'm trying to get the sidebar to work with a different code that is inside a php code. I tried using the above < ?php dynamic_sidebar( 'pop-photos-sidebar' ); ? > code and it broke my site since the php dynamic_sidebar code is inside another php code. So I tried making a $ function like so:

$newssidebar = dynamic_sidebar( 'pop-news-sidebar' );
            echo '<div class="sidebar sidebar-first">
                <ul class="widget-area first">
                '.$newssidebar.'
                 </ul>
             </div>';

This sucesfully displayed the dynamic side bar "pop-news-sidebar" but.. it is not inside the ul class widget-area first, or inside the div class sidebar sidebar-first. How would I make my dynamic sidebar to properly be displayed in the ul class and div class listed above like it should be? Would I even use echo? I didn't think it was necessary to paste the full code, but here it is anyways:

<?php
    if( fake if code ) {
        if( another fake if code ) {
            $newssidebar = dynamic_sidebar( 'pop-news-sidebar' );
            echo '<div class="sidebar sidebar-first">
                <ul class="widget-area first">
                '.$newssidebar.'
                </ul>
            </div>';
        }else if( fake else ) {
            echo 'some other code';
         }
    }

?>

Any help would tremendously be appreciated! :)

share|improve this question
    
Can you post your actual code, so we can see your call to dynamic_sidebar() in context of your actual code? –  Chip Bennett Dec 12 '12 at 19:33

1 Answer 1

up vote 0 down vote accepted

You don't need to echo dynamic_sidebar(). End your echo, call dynamic_sidebar(), and then start a new echo. To make it easier, just close/reopen your PHP tags:

<?php
if( fake if code ) {
    if( another fake if code ) {
        ?>
        <div class="sidebar sidebar-first">
            <ul class="widget-area first">
                <?php dynamic_sidebar( 'pop-news-sidebar' ); ?>
            </ul>
        </div>
        <?php
    } else if( fake else ) {
        echo 'some other code';
    }
}    
?>
share|improve this answer
    
Wow, so simple yet effective and great, your the man Chip! I'll accept the answer in 5 minutes! :) –  I am not a Frog Dec 12 '12 at 19:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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