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?
- How to show page content in feed?
- apply_filters() and the_excerpt are giving unexpected results
- remove_filter( ‘the_content’, ‘wpautop’ ); only for certain post types
- Valid characters for actions, hooks and filters
- How do I filter the excerpt metabox description in admin?
- How do I use the ‘http_request_host_is_external’ filter
- AJAX filter posts on click based on category
- Can I add custom meta for each image uploaded via media-upload.php?
- I’m using a filter to remove the tags auto wrap, but there still wrapped elements?
- Format content value from DB outside of WordPress filters
- Can’t change the title tag with wp_title filter
- How to filter ‘post_gallery’ after all other filters/plugins etc
- Cron schedule interval through plugin options?
- wpmu_signup_user_notification filter not working
- Filter oembeds tags to modify iframe attributes
- Removing labels and tag on WordPress’s default login form
- How to add data- attribute to tag
- How to check a filter are applied
- Add $more_link_text parameter to the_excerpt()
- How do I add a listbox to the TinyMCE editor?
- How to remove google font in WordPress for only single page?
- Why anything done on comments_array hook gets reset?
- How to add a class to Tag cloud widget link?
- Is there a get_post(s) filter that can alter/replace the output completely?
- get_header and hook avoid normal call
- Dropdown filter in custom posts
- Modify WP_Post before processing
- How to order by taxonomy using wp_query
- Filter taxonomy admin pagination
- Feed, RSS not able to clear the cache and cannot change the limit of cache life time
- WP action/filter to modify title before header output and article output?
- Custom view counts not updating correctly
- Using wp_handle_upload() to Direct Specific Path by Using $overrides
- To add a custom filter based on a meta field
- How to create Woocommerce Product Filter Widget [closed]
- Add default user field to WooCommerce checkout [closed]
- Filtering Comment Reply Links (comment_reply_link_args) for “infinite replies” in nested comments
- Create Search Form to Filter Through Terms
- Formatting get_post content doesn’t allow JS content to function properly
- Woocommerce “added to cart” message on main(home) page
- Is it possible to apply filter to meta key value when querying posts?
- Add filter for specific post type only
- How to add_filter to an OOP based apply_filter(‘foo::bar’, $a);
- apply_filters with multiple args and multiple add_filter
- Avoid user registrations with specific email provider
- Should I remove_filter in order to replace a filter?
- How can I specify the post status of an untrashed post?
- Conflict calling an add_filter() twice
- Filter for author list in gutenberg core editor
- Rewrite rule and display of post
- Passing variable from child theme function to parent theme filter
- paginate_links() Change the order of links
- Filter / add_action to upgrade.php page
- How to disable a wp filter in a certain admin panel page
- Why does admin_body_class not work?
- Problem width wp_insert_post_data and Gutenberg block editor
- add_filter doesn’t return false?
- How to track a particular page in order to address the loading speed issue
- how to overwrite next_post_link
- Print url to default featured image
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- What action/filter can be used for modifying the page to be rendered?
- Adding user filter – Not updating data in URL
- How to check which submission button was clicked?
- filter wptexturize doesn’t work on old posts titles
- remove_action conditionally for Custom Post Type – not working
- wp_get_attachment_link filter not working
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- Getting entry ID from frm_email_message filter in formidable
- Is there a hook or filter that adds a button to the left of the search box?
- Filter and manipulate the get_current_user() function