You should use ob_start()
and ob_get_clean()
for that. Also it looks like you’re not using any attributes so you can ditch the call to shortcode_atts()
<?php
// List judges shortcode
function judges_shortcode($atts){
ob_start();
the_content();
$judges = get_posts(array(
'numberposts' => -1,
'post_type' => 'judges',
'meta_key' => '',
'meta_value' => ''
));
if ($judges) { ?>
<div class="container">
<div class="row">
<?php foreach ($judges as $post) { setup_postdata( $post ); ?>
<?php
$image = get_field('judge_image');
$link = get_field('judge_link');
$socialicon = get_field('judge_social_icon');
?>
<div class="col">
<ul class="judges d-flex">
<li class="judge">
<h3 class="text-center"><a href="https://wordpress.stackexchange.com/questions/325765/<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<img src="<?php echo $image['url']; ?>" alt="" />
<p><?php the_content(); ?></p>
<a class="judge-link" target="_blank" href="<?php echo $link ?>"><?php echo $socialicon ?></a>
</li>
</ul>
</div>
<?php } wp_reset_postdata(); ?>
</div> <!-- end row -->
</div> <!-- end container -->
<?php };
return ob_get_clean();
}
add_shortcode('judges','judges_shortcode');