Advanced WordPress Excerpt Function

Here is how to setup a custom WordPress excerpt function with the following criteria:

  • This will allow you to limit the amount of characters displayed in the excerpt
  • While limiting the number of characters displayed this will prevent the last word from getting cut off.  In other words it will limit the number of characters but fully display the last word
  • Show “read more” or “…” text after the excerpt
  • If there is NOT more to read – meaning if the post length is shorter than the number of designated characters in the excerpt – it will not show a “…” or “read more” text

Here is how this is done.  First, put the following snippet of code in your functions.php file:

The section above that says:

is where you would put your html to make it says “Read more” or whatever you want.

Next, you can call the excerpt in your theme file using this code:

The number “400” is your character limit designation. So if you want the excerpt to show only 50 characters change that number to “50”.

Leave a Reply