<div id="contenitore-related-posts">

  <?php foreach($related_posts as $p){
      $parole_da_mostrare = 40;
      $post_link = get_the_permalink($p->ID);
      $post_thumbnail = get_the_post_thumbnail($p->ID,'thumbnail',['alt' => substr($p->post_title, 0, 80) . '...']); // Nella variabile è già incorporato tutto l'html
      $post_title = $p->post_title;
      $post_except = wp_trim_words($p->post_content, $parole_da_mostrare); // Versione custom non nativa wp
  ?>

  <div class="row related-post-row <?php echo wp_is_mobile() ? 'is-mobile' : '';?>">
    <div class="col-12 col-md-3 related-col-img <?php echo wp_is_mobile() ? 'is-mobile' : '';?>">
      <?php echo $post_thumbnail ;?>
    </div>
    <div class="col-12 col-md-9 related-col-content <?php echo wp_is_mobile() ? 'is-mobile' : '';?>">
      <a href="<?php echo $post_link; ?>" title="<?php echo wp_kses_post($p->post_title); ?>"><?php echo wp_kses_post($p->post_title); ?></a><br>
      <?php echo wp_kses_post($post_except); ?>
    </div>
  </div>

  <div class="row">
    <div class="col-md-12">
      <hr>
    </div>
  </div>
  <?php } ?>

</div>