Preserve post/page formatting with limited character

$my_id = 162;
$post_id = get_post($my_id);
$content = $post_id->post_content;
$content = apply_filters(‘the_content’, $content);
$content = str_replace(‘]]>’, ‘]]>’, $content);

//all content from the post.
echo $content;

//limited characters from the post.
echo $content = substr($content,0,300);

Leave a Reply

Your email address will not be published.