I'm trying include dynamic sidebar to Uncode Theme. I created child template, then I created all files and now I have a piece of code who shows content and sidebar area.
In functions.php
I created dynamic sidebar:
add_action( 'widgets_init', function () {
$args = array(
'name' => __( 'Sidebar Messages Single', 'uncode' ),
'id' => 'sidebar-messages-single',
'description' => '',
'class' => 'dynamic-widget',
'before_widget' => '<li id="dynamic-sidebar" class="widget">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>'
);
register_sidebar( $args );
});
Then in single-portfolio.php
I'm trying include that sidebar.
$sidebar_widgets = is_active_sidebar( 'sidebar-messages-single' ) ? dynamic_sidebar( 'sidebar-messages-single' ) : null;
$the_content = '<div class="row-container">
<div class="row row-parent' . $row_classes . $limit_content_width . '">
<div class="row-inner">
' . (($layout === 'sidebar_right') ? $main_content : '') . '
<div class="col-lg-' . $sidebar_size . '">
<div class="uncol style-' . $portfolio_style . $expand_col . $sidebar_padding . (($sidebar_fill === 'on' && $portfolio_bg_color !== '') ? '' : $sidebar_sticky) . '">
<div class="uncoltable' . (($sidebar_fill === 'on' && $portfolio_bg_color !== '') ? $sidebar_sticky : '') . '">
<div class="uncell' . $sidebar_inner_padding . '">
<div class="uncont">
<div>
' . $sidebar_widgets . '
</div>
' . $footer_content . '
</div>
</div>
</div>
</div>
</div>
' . (($layout === 'sidebar_left') ? $main_content : '') . '
</div>
</div>
</div>';
It seems to me everything is alright, but when I render page I get this result.
The place where sidebar should be render I get int (one). Whereas sidebar is rendered in another place.
At first I thought it is DOM manipulated via JavaScript, but when I debugged and disabled JS it worked the same.
Furthermore, when I added normal string to <div>
beside variable $sidebar_widget
. String rendered in correct place.
Thanks a lot for help!
dynamic_sidebar()
into a variable like that. That function echoes its results. Is there a particular reason you've built your template as a giant string?dynamic_sidebar
cannot be saved in a variable, because it always echoes out the widget, you have to add it directly within your markup