Changing the excerpt length…

screen with written code

…and customizing the “read more” link.

Easy task even for a beginner, especially changing the excerpt length. You must be familiar with the commands you need in order to make it work and it goes like this:

Adding a read more link (replace the default square brackets – three dots with a link to the full post), makes your content more readable and improves visitor’s user experience. One way to do that is by adding the following code into your functions.php file:

In this case you apply the excerpt_more filter. For more information visit:

We can go a little bit deeper by using classic php commands and create our custom excerpt. This can help us in cases where the traditional wordpress excerpt doesn’t work and we need to reduce the amount of content we want to display in our front page with a clever link to the full content. In a project I was working on, because I wanted to show the excerpt for a post format other than the standard, let’s say the chat post format, using the $post global variable and combining the substr() php function with some wordpress commands I took the length of the content, reduced it to fit my needs and came up with the following code that I added to my functions.php file:

The above code first checks if it’s a single post (we could use different conditions), and if it’s not, it checks if it has a post format of chat, then it takes the content string, counts 250 first characters (not words), discards the rest, concatenates a more link which is some html code with text and a permalink ( get_permalink( $post->ID ) ) that points to the full post by retrieving it’s post ID and finally returns the result. Simple stuff.