Search code examples
phpecho

Echo gives different output from only html


I have this code:

 echo " <div class=\"col-md-4 col-lg-3\"> "
                   . get_sidebar() ."
                </div> ";

when I use it, sidebar doesnt show like col-md-4, it is full width.I want to use it as a sidebar.

but when I use the below html code instead of php function, page seems like how I want:

 <div class="col-md-4 col-lg-3">
                    <?php get_sidebar(); ?>
                </div>

what is the problem?


Solution

  • Problem is, that the function get_sidebar() is making echo by itself. It is not returning HTML code, which you could join with your HTML code.

    This should work:

    echo '<div class="col-md-4 col-lg-3">';
    get_sidebar();
    echo '</div>';