You’re using a mix of echoing and returning.
Here you’re starting by echoing:
echo '<div class="clear"></div>';
Here you’re putting the output into a variable (correctly):
$output="<div class="row">";
And here you’re just writing the content in quotes without echoing or assigning to a variable:
'<div class="col-md-8 grid-entry-wrapper"> <!-- grid-entry-wrapper open -->
<!-- BLOG LOOP -->
</div><!-- grid-entry-wrapper close -->';
Shortcodes need to return
the entirety of their output. So you either need to build up a variable like the second example all the way through, or use output buffering to ‘capture’ the output to return later.
Here’s an example of what you’re doing but using output buffering:
function blog_loop_feat( $atts ) {
$args = array();
$splendid_query = new WP_Query( $args );
ob_start();
?>
<div class="clear"></div>
<div class="row">
<?php while ( $splendid_query->have_posts() ) : $splendid_query->the_post(); ?>
<div class="col-md-8 grid-entry-wrapper"> <!-- grid-entry-wrapper open -->
<!-- BLOG LOOP -->
</div><!-- grid-entry-wrapper close -->
<?php endwhile; wp_reset_query(); ?>
<div class="col-md-4">
<?php if ( ! function_exists('dynamic_sidebar') || ! dynamic_sidebar("Featured sidebar") ) : endif; ?>
</div>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'blog_loop_feat', 'blog_loop_feat' );
ob_start()
starts capturing the output, and ob_get_clean()
gets the captured output, which in this example is returned at the end of the function.