I would to retrieve a specific number of words from post_content, but I don’t want the tags stripped.
I was using wp_trim_words() before I realised that all my images are being removed, so I need an alternative way of doing it.
I would to retrieve a specific number of words from post_content, but I don’t want the tags stripped.
I was using wp_trim_words() before I realised that all my images are being removed, so I need an alternative way of doing it.
Comments are closed.
I don’t think there is an excerpt type function that let you keep images. But there is functions to do what you want to do.
First you need to set up your excerpts. In your content.php file change
with
Use
to set your excerpt length if you need anything other than the wordpress default of 55 words
The following functions will add the first image of your post to the excerpt and keep its aspect ratio. Add to functions.php
Now add the following lines
just above
in content.php. To set a personal size for your image, just set the value = 250 in the last set of code to any size you want. Keep the value = 0 as is. This is to keep the aspect ratio of your image.
Here are some styling to set padding
Hope this helped.