How to define the exerpt lengt for post preview in WordPress?

If you have set the “Latest Posts” view as the homepage of your WordPress blog, you can adjust how many posts per page should be displayed via the dashboard. However, the length of the excerpt for each post is set to 55 words.

With the help of this function, you can set the preview length of your blog posts regardless of the theme you are using:

  1. Go to the dashboard of your WordPress website.
  2. Navigate to “Appearance” > “Theme Editor”.
  3. Select the functions.php file of your current theme from the right sidebar.
  4. Insert the following code at the end of the file.
  5. In the code, replace 19 with the number of words you want in the preview.
function custom_excerpt_length($length) {
return 19;
}
add_filter('excerpt_length', 'custom_excerpt_length', 999);

Leave a Comment