Dynamic HTML not displaying at respective place
I have a created shortcode in function.php
and my code is,
function Post_home(){
$data='<div class="cp-seeWrapper"><div class="container"><div class="row"><div class="col-xl-8 col-lg-8 col-md-8 col-sm-12 col-xs-12">';
//some logic here
$data.='</div>';
$data.='<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12"><div class="cp-social">';
if (is_active_sidebar('footer-social')) :
dynamic_sidebar('footer-social');
endif;
$data.='</div><div class="cp-newsletter">';
if (is_active_sidebar('cp_newsletter')) :
dynamic_sidebar('cp_newsletter');
endif;
$data.='</div></div></div></div></div>';
return $data;
}
add_shortcode( 'home_post', 'Post_home' );
Now just notice here, Whatever I am adding the logic part that output is displaying before the parent div. I mean my parent div is cp-seeWrapper
and output is displaying before it.
I added footer-social and newsletter logic and both are displaying above parent div.
Would you help me out?
My output is
//I am getting my output here
<div class="cp-seeWrapper">
<div class="container">
<div class="row">
<div class="col-xl-8 col-lg-8 col-md-8 col-sm-12 col-xs-12">
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12">
<div class="cp-social"></div>
<div class="cp-newsletter"></div>
</div>
</div>
</div>
</div>
I have created widget on function.php
function cp_newsletters() {
register_sidebar( array(
'name' => 'Newsletter',
'id' => 'cp_newsletter',
'before_widget' => '<div class="chw-newsletter">',
'after_widget' => '</div>',
'before_title' => '<h2 class="chw-newsletter_title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'cp_newsletters' );
dynamic_sidebar()
echoes the sidebar's widgets.ob_start()
as in my answer..