Probleme shortcode with list author

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' );

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

This is because output buffers are closed, but they’re never opened.

Adding this at the beginning of the shortcode will fix things:

ob_start();


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x