How to limit WordPress Post content length?

Sometimes, we only want to show initial WordPress post content on the site. There are many ways to limit the WordPress post content length. One way is to replace WordPress the_content() in WordPress template files with following code.

$article_data = substr(get_the_content(), 0, 300);
echo $article_data;


get_the_content() function contains wordpress content page/post content. Then it will pass it to php substr() function to limit the content to 300 characters. Then you can display wherever you want.

Learn more about the similar topics:
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.