How to return loop contents
There are replacements that return pure strings for all parts, no need to print anything into an output buffer. I like sprintf() and would write your example like this: <?php if ( $cms_pl_pages->have_posts() ) { $content=”<section class=”cms-pl-gallery”>”; while ( $cms_pl_pages->have_posts() ) { $cms_pl_pages->the_post(); $content .= sprintf( ‘<article class=”cms-pl-item clearfix”> %1$s <h2> <a href=”https://wordpress.stackexchange.com/questions/57000/%2$s” title=”Read %3$s”>%4$s</a> … Read more