title: How to fix a shortcode to display its content in the correct location?
body: <p>I am trying to create a shortcode that will display some information based on the 
   <a href="http://schema.org/Person" rel="nofollow noreferrer">Schema.org Person Type</a>.</p>
  
  <p>I created this simple test shortcode that will echo one phrase. The phrase is: <code>Personal Info</code>. Here is the code:</p>
  
  <pre><code>function add_schema_person_shortcode() {
          echo '&lt;div class="schema_person_microdata_container"&gt;';
              echo '&lt;div itemscope itemtype="http://schema.org/Person"&gt;'; 
                  echo '&lt;h3&gt;'; echo 'Personal Info'; echo '&lt;/h3&gt;';
              echo '&lt;/div&gt;';
          echo '&lt;/div&gt;';
  }
  add_shortcode( 'schema-person-shortcode', 'add_schema_person_shortcode');
  </code></pre>
  
  <p>My problem is that the phrase <code>Personal Info</code> is displayed on top of all content, even if there is content above the shortcode.</p>
  
  <p><a href="https://audio.coptic-treasures.com/shortcode-test/" rel="nofollow noreferrer">Please refer to this test post by clicking here.</a></p>
  
  <p>The post content is:</p>
  
  <pre><code>&lt;p&gt;this is text written ABOVE the shortcode.&lt;/p&gt;
  [schema-person-shortcode]
  &lt;p&gt;this is text written below the shortcode.&lt;/p&gt;
  </code></pre>
  
  <p>However, what is displayed in the front end is:
  <a href="https://i.stack.imgur.com/8oZYI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8oZYI.png" alt="enter image description here"></a></p>
  
  <p>As I don't have any special code to force the shortcode content to display at the page top, I am unable to determine where is the error.</p>
  
  <p>I'd appreciate if someone can point me to the right direction on how to fix this problem and get the shortcode content to display in its correct location.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I got an excellent answer from @Andrew Schultz below, but it works for me only when I want to display text. I had added a dummy code to my original question to make it easy.</p>
  
  <p>However, my full code has if statements, so I am pasting the full code below, to help getting a solution when there are if statements in the code.</p>
  
  <p>Thanks.</p>
  
  <pre><code>function add_schema_person_shortcode() {
      if (ICL_LANGUAGE_CODE == 'ar') { 
  
          if( function_exists( 'types_render_field' ) ){
  
              $author_info = array_filter( array (
                      'honorificPrefix' =&gt; types_render_field( "schema-person-honorific-prefix", array () ),
                      'givenName'       =&gt; types_render_field( "schema-person-given-name", array () ),
                      'familyName'      =&gt; types_render_field( "schema-person-family-name", array () ),
                      'honorificSuffix' =&gt; types_render_field( "schema-person-honorific-suffix", array () ),
                      ) );
  
              $author_additional_name = array_filter( array (
                      'additionalName' =&gt; types_render_field( "schema-person-additional-name", array () ),
                      ) );        
  
              $person_monastic_name = array_filter( array (
                      'additionalName' =&gt; types_render_field( "schema-person-monastic-name", array () ),
                      ) );        
  
              $person_date_of_birth = array_filter( array (
                      'birthDate' =&gt; types_render_field( "schema-person-date-of-birth", array () ),
                      ) );
  
              $person_place_of_birth = array_filter( array (
                      'birthPlace' =&gt; types_render_field( "schema-person-place-of-birth", array () ),
                      ) );        
  
                  if ( ! empty( $author_info ) ) {
  
                      echo '&lt;div class="schema_person_microdata_container"&gt;';
                          echo '&lt;div itemscope itemtype="http://schema.org/Person"&gt;'; 
                          echo '&lt;h3&gt;'; echo 'كارت التعريف بالشخصية'; echo '&lt;/h3&gt;';
                          echo '&lt;table class="schema_book_microdata_table"&gt;';
                              echo '&lt;tr&gt;';
                                  echo '&lt;th class="schema-book-table-initial-column"&gt;'; echo 'البيانات'; echo '&lt;/th&gt;';
                                  echo '&lt;th&gt;';echo 'التفاصيل'; echo '&lt;/th&gt;';
                              echo '&lt;/tr&gt;';                   
                              echo '&lt;tr&gt;&lt;td&gt;الأسم&lt;/td&gt;&lt;td&gt;';
                                  foreach ( $author_info as $prop =&gt; $value ) {
                                  printf( '&lt;span itemprop="%s"&gt; %s &lt;/span&gt;', $prop, $value );
                                  }
                                  echo '&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;';
  
  
                              if ( ! empty( $author_additional_name ) ) {
                                  echo '&lt;tr&gt;&lt;td&gt;الأسم قبل الرسامة&lt;/td&gt;&lt;td&gt;';
                                  foreach ( $author_additional_name as $prop =&gt; $value ) {
                                  printf( '&lt;span itemprop="%s"&gt; %s &lt;/span&gt;', $prop, $value );
                                  }
                                  echo '&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;';
                              }
  
                              if ( ! empty( $person_monastic_name ) ) {
                                  echo '&lt;tr&gt;&lt;td&gt;الأسم الرهباني&lt;/td&gt;&lt;td&gt;';
                                  foreach ( $person_monastic_name as $prop =&gt; $value ) {
                                  printf( '&lt;span itemprop="%s"&gt; %s &lt;/span&gt;', $prop, $value );
                                  }
                                  echo '&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;';
                              }
  
                              if ( ! empty( $person_date_of_birth ) ) {
                                  echo '&lt;tr&gt;&lt;td&gt;تاريخ الميلاد&lt;/td&gt;&lt;td&gt;';
                                  foreach ( $person_date_of_birth as $prop =&gt; $value ) {
                                  printf( '&lt;span itemprop="%s"&gt; %s &lt;/span&gt;', $prop, $value );
                                  }
                                  echo '&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;';
                              }
  
                              if ( ! empty( $person_place_of_birth ) ) {
                                  echo '&lt;tr&gt;&lt;td&gt;محل الميلاد&lt;/td&gt;&lt;td&gt;';
                                  foreach ( $person_place_of_birth as $prop =&gt; $value ) {
                                  printf( '&lt;span itemprop="%s"&gt; %s &lt;/span&gt;', $prop, $value );
                                  }
                                  echo '&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;';
                              }
  
  
  
                          echo '&lt;/table&gt;';
                          echo '&lt;/div&gt;';
                      echo '&lt;/div&gt;';
                  }
          }
  
      }
  }
  add_shortcode( 'schema-person-shortcode', 'add_schema_person_shortcode');
  </code></pre>