Checking to see if content is bigger than excerpt in WordPress

The problem: I need to check if my content was bigger than the excerpt in order to know whether or not to add a read more button.
The solution: This one was a bit tricky for me, but in the end with the help of the almost “all-knowing” Google, I found an answer. This here is my code:

 

So what happens here is:
– I first declare 2 variables to get both the actual content and the excerpt
– on the lines 5-8 I check if the post has a featured image and if so, I display it
– then on lines 9-13 I write an if statement to check if the actual content of the post is bigger than the one of the excerpt with the help of the mb_strlen function and I display either accordingly.

The rest of the code should be self self-explanatory.

Share: Facebook Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *