I have created a list of my contributors for my website it works well. I'm trying to do this with a shortcode in my functions.php. The list appears well. But when I want to place it in my theme in any page, it appears before the content whereas I want it to be at the bottom of the page of its appropriate page template. I can't seem to find my mistake
function comite_shortcode( $atts ){
$contributor_member = array(
'role' => 'Contributor',
'orderby' => 'user_nicename',
'order' => 'ASC',
'number' => 2,
);
$authors = get_users($contributor_member);
foreach ($authors as $users):
echo '<div class="column-member">';
echo '<div class="info-member">';
echo '<span class="comite-description-name">'.$users->display_name.'</span>';
echo '<span class="comite-description">'.$users->institution_rattachementUser.'</span>';
echo '<span class="comite-description">'.$users->fonctionUser.'</span>';
echo '<span class="comite-description">'.$users->responsableUser.'</span>';
echo'</div>';
echo'</div>';
echo'<hr class="separator-member">';
endforeach;
$html = ob_get_contents();
return $html; // On renvoie le contenu }
add_shortcode( 'comite', 'comite_shortcode' );
I have created a list of my contributors for my website it works well. I'm trying to do this with a shortcode in my functions.php. The list appears well. But when I want to place it in my theme in any page, it appears before the content whereas I want it to be at the bottom of the page of its appropriate page template. I can't seem to find my mistake
function comite_shortcode( $atts ){
$contributor_member = array(
'role' => 'Contributor',
'orderby' => 'user_nicename',
'order' => 'ASC',
'number' => 2,
);
$authors = get_users($contributor_member);
foreach ($authors as $users):
echo '<div class="column-member">';
echo '<div class="info-member">';
echo '<span class="comite-description-name">'.$users->display_name.'</span>';
echo '<span class="comite-description">'.$users->institution_rattachementUser.'</span>';
echo '<span class="comite-description">'.$users->fonctionUser.'</span>';
echo '<span class="comite-description">'.$users->responsableUser.'</span>';
echo'</div>';
echo'</div>';
echo'<hr class="separator-member">';
endforeach;
$html = ob_get_contents();
return $html; // On renvoie le contenu }
add_shortcode( 'comite', 'comite_shortcode' );
Share
Improve this question
edited Oct 5, 2020 at 18:16
Tom J Nowell♦
61k7 gold badges79 silver badges148 bronze badges
asked Oct 5, 2020 at 18:00
DimDim
31 bronze badge
3
|
1 Answer
Reset to default 0This is because output buffers are closed, but they're never opened.
Adding this at the beginning of the shortcode will fix things:
ob_start();
ob_get_contents
to close your output buffer but where did you start it? I can't find anob_start
call in your shortcodes function – Tom J Nowell ♦ Commented Oct 5, 2020 at 18:17ob_start
it's outputting directly to the browser, which is broken behaviour. But it appearsob_get_contents
still works despite this – Tom J Nowell ♦ Commented Oct 5, 2020 at 19:01