1

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! :)

1
  • Can you post your actual code, so we can see your call to dynamic_sidebar() in context of your actual code? Dec 12, 2012 at 19:33

1 Answer 1

1

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';
    }
}    
?>
1
  • Wow, so simple yet effective and great, your the man Chip! I'll accept the answer in 5 minutes! :) Dec 12, 2012 at 19:40

Your Answer

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

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