Question

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' );
Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top