How to include html tags within a wordpress excerpt?
Solution 1
As I see it, you can only use method 2 and 3; both of them can be updated via WordPress' back-end with virtually no programming required which is ideal if you're going to be installing and using them on client sites.
Here's a tutorial with working code for method 3 -- http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/ and here's a plugin to use method 2 -- http://wordpress.org/extend/plugins/advanced-excerpt/
Solution 2
I use the following statement sometimes to get the first 55 words of a post content.
implode(' ', array_slice(explode(' ', get_the_content()), 0, 55));
Daryl
Updated on September 26, 2022Comments
-
Daryl over 1 year
Currently in a wordpress template, if you use the code
the_excerpt()
it will display the first 55 words of a post and strips all html from the post.I need to include
<a href...
tags in the excerpt so that links are still visible.Existing methods include:
- Hacking the wordpress core - definitely not an option.
- using a plugin - don't want to use, it's dependent on the developer keeping the plugin up to date
- writing code within functions.php to re-write the excerpt filter. - I'd prefer not to use this as it might have to be changed in future versions of WP
Is there a filter hook or other known method to include html easily without hacks?
All help is appreciated! Cheers.
-
theflowersoftime over 11 yearsThis uses a completely different field.
-
Steve about 10 yearsThe plugin for method 2 hasn't been updated in 2 years. Wondering if it's still current.
-
stealthyninja about 10 years@Steve -- Since my answer was posted three years ago, probably not. wordpress.org/plugins/easy-custom-auto-excerpt or wordpress.org/plugins/sem-fancy-excerpt that might be able to do a similar job if you tried installing the other plugin and it didn't work on your version of WordPress.
-
chriOSx about 6 yearsFinally someone with a practical and easy solution for this issue.. Thanks.