how to shorten the_content in wordpress

  • <?php echo wp_trim_words( get_the_content(), 40, ‘…’ ); ?>
  • $last_space = strrpos( substr(get_the_excerpt(), 0, 216 ), ‘ ‘ );
    $cnt1 = substr(get_the_excerpt(),0,$last_space);

    echo $cnt1;