I posted an article about this a while ago:
function wp_trim_all_excerpt($text) {
// Creates an excerpt if needed; and shortens the manual excerpt as well
global $post;
$raw_excerpt = $text;
if ( '' == $text ) {
$text = get_the_content('');
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
}
$text = strip_tags($text);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'wp_trim_all_excerpt');
Related Posts:
- Get excerpt from $post->post_content
- How to use the_excerpt in a filter hook?
- End excerpt at the end of the sentence
- get_the_excerpt() with fallback like the_excerpt()
- How do I filter get_the_excerpt() but keep all of its functionality intact?
- Buddypress: Edit activity when new blog post [closed]
- Why in archive page doesn´t show read more button with excerpt?
- the_excerpt filter with an empty excerpt
- Access get_the_title() from ‘excerpt_length’ filter
- Give “Read More” precedence over excerpt() word count
- How do I override the_excerpt so that it will display full content?
- the_excerpt filter doesn’t work as expected
- Excerpt is being added above the content, but it should be after it
- run shortcode in excerpt of single custom post type
- apply_filters(‘get_the_content’, $content) + Except
- Trimming a custom field to a length
- Adding html banner to posts
- Apply wordpress filter checking category
- Add Filter – Pass Variable (PHP < 5.3)
- Filter Post Title without affecting screen-reader-text
- Create different flavours of excerpt
- Cutting off excerpt with first sentence
- Auto-generated excerpt with shortcode and read more button/text link
- Read More in the actual excerpt
- is_page_template() doesn’t work with excerpt_length filter
- the_excerpt() does not work with has_excerpt()?
- get_the_excerpt on mobile still displays continue reading
- Custom excerpt_more filter not working when tag is present
- Why does using excerpt_more filter change link location?
- Not able to change wp_title using add_filter
- How to hook a filter to catch get_post_meta when alternate a custom field output?
- Changing JPEG compression depending on image size
- Advanced Custom Fields and Yoast SEO keyword analysis [closed]
- Insert Custom HTML After Shortcode
- Is there a way to add another row to the tinyMCE kitchen sink toggle?
- add_filter to youtube embeds?
- How can I detect if a user changes their password?
- SSL certificate for the host could not be verified
- Store source permalink on XMLRPC calls
- How can I hide all posts that don’t have a thumbnail?
- Restrict filter to run only inside specific function
- Setting title using wp_title filter
- 4.0 remove_filter for WordPress core function not working for me
- How do I add a current class to the current post?
- How apply_filters work in WordPress?
- Apply a filter only once
- option_active_plugins filter not working
- How do we check if the user is logging in or registering?
- Add a header before fields added with the attachment_fields_to_edit() filter
- Are there Limitations on filter handles?
- Hide content editor for posts after approriate date
- Custom excerpt length filter doesn’t work
- Same Conditionals Not Working on Two Different Hooks
- remove_action in plugin file
- How to apply filter at search of woocommerce products?
- Variables in post title
- Filtering post-formats from the loop using new WP-Query();
- How to edit dashboard search posts button texts for my CPT?
- When does a function assigned to the content_filtered_edit_pre filter hook fire?
- Capture post content before page renders
- Empty string supplied as input when parsing content
- How can I remove the kses filters when saving a specific post type ? (it breaks my JSON)
- Remove_action does not work
- How to pass variables to custom filter from multiple functions
- WooCommerce Custom Product Validation [closed]
- Make WP not format code, not insert line breaks in between tags
- the_content filter together with require_once returns 1 instead of the content of the included file
- Missing Argument 2 for apply_filter
- How to get a single hook from wp_head()?
- Detect when gutenberg editor title is available in Dom after editor load
- How to apply a filter to an ACF wysiwig editor field output?
- Is it possible to bind a function to a filter hook via Ajax?
- Hide Posts In Back-end/Admin Based On User’s (Pseudo) Privileges Controlled by ACF
- Filter Pages by Custom Field (ACF) in admin area
- Remove tags without a specific meta key from “choose from the most used tags”
- Which Filter Do I Use To Modify The Subject Of The Retrieve Password Notification Email?
- Register users by e-mail
- automatic title through filter
- Filter causing loss of _wp_attachment_metadata
- Buddypress Filter Multiple Activities [closed]
- How do I check if I can use the allowed_block_types filter?
- Having wp-admin on different domain
- oembed_dataparse filter not running at all for standard YouTube embed
- Action for opening attachment or manipulating all attachment links
- Filter wp_mail based on content type
- Hide disclaimer from summary excerpts
- How to apply filter
- Remove the post_content search from WHERE clause (and CONCAT sql function)
- mu-plugins body_class filter not working
- Post filter Month dropdown at front-end like wordpress backend
- shortcode function outputs multiple anchor tags
- WP Dashboard -> Posts-> Filter by Category -> Form Method Change : Which Hook
- Show child theme for users on specific IP
- wp.getPosts with status = ‘trash’ using node.js
- Is there a way to overwrite a filter used in canonical.php?
- How do I remove certain HTML elements with specific classes from the feed?
- Adding an orderby filter, casting postmeta with multiple keys
- confusion with add_filter
- post->post_content filter
- How to change this WP logo and posts url in block editor?