excerpt_length is only applied to generated excerpts— excerpts automatically generated from the post body.
To trim your manually created excerpt, use the same function that trims the generated one— wp_trim_words.
if(has_excerpt()) {
$length = apply_filters('excerpt_length',20);
echo wp_trim_words(get_the_excerpt(),$length);
} else {
the_content();
}
Related Posts:
- Get excerpt from $post->post_content
- How to use the_excerpt in a filter hook?
- add_filter on “the_excerpt” only works when post does not have excerpt
- 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
- 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?
- Why doesn’t remove_action work in my plugin?
- Using a filter to modify Genesis wp_nav_menu
- Upload restrictions – upload_mimes – filter: Adding multiple MIMEs for a single extension and adding multiple extensions for a single MIME type?
- Filters on Login Page
- How can I change the email that is inside the default email texts of wordpress?
- What is the earliest hook to modify post content?
- How to modify only part of a function through the filter
- Modify message displayed on post save
- Something is filtering my shortcodes… Can’t figure out what
- How can I apply filters in my class that extends Walker_Nav_Menu?
- Pass debug_backtrace() in WordPress filter
- How should I be using filters and is_single together?
- Remove actions/filters that are set with create_function()
- How to edit embed filter for youtube video to allow responsive full width layout
- Remove get_template_part() from custom theme
- How to access page variable inside action hook
- I need to hook and change language of facebook sdk
- change “missing attachment” text functions.php
- Use has_filter on comment_post
- Hook in a sidebar widget and add some markup
- preg_match() not working with post content
- return get_the_tag_list with whitespace removed
- How do I add tags to entire comments, not just their text
- ‘manage_users_custom_column’ is a filter, but ‘manage_posts_custom_column’ is an action. Why?
- comment_notification_text filter not working
- Line Breaks are stripped off when direction property is found
- Modify author url display in edit-comments.php
- WordPress remove_filter not working
- How to exclude or include categories in wp rest API without query parameters?
- Remove and replace woocommerce add to cart button [closed]
- add_filter( ‘the_title’ gets through this if statement twice
- Changing the category for existing Gutenberg blocks
- Hook to change the site URL
- Replace a specific URL on all apperances on the Website (Maybe a filter?)
- Modify WordPress Page Title ()
- How to add lazy field in content endpoint using Gutenberg blocks
- Strange behaviour of REGEX in a WordPress filter (trying to suppress emtpy paragraphs)
- Modify Contextual Help
- how to use apply filter for Class?
- How can I see exactly what arguments are being passed through a filter so that I may modify them?
- Widget image reorganize layout
- WordPress set featured image to first image of the post
- Modify WordPress search behaviour in backend?
- Set Microsoft Word links to open in new window/tab
- WordPress get_avatar filter to match logins
- Modify category listing API response
- How to make an If Else on Excerpt Filter
- Converting restricted html in comments to bbcode
- What is the proper/best way to have multiple add_filter for wp-job-manager-resume
- I can get the permalink or the excerpt to work correctly, but not both
- Modify WooCommerce email shipping text value
- Change shortcode output (filter?)
- How do I add a class to all sidebars to let a Google Custom Search Engine know not to index the content?
- How to replace all images in all posts and pages with a different size?
- Using Filters To Change Page Title
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- using posts_where for meta data on pre_get_posts
- Updating User Profile on Registration
- add_filter with specific thumb names
- Override typo in multiple parent theme files?
- Replace image scr with it’s surrounding href
- WooCommerce comments_template Filter Not Firing
- Woocommerce: Only one review per verified buyer [closed]
- str_replace css meta tag?
- Footnotes with dynamic title attributes?
- Can you call a filter hook by “add_action”?
- Filter widget_pages_args not working in Pages Widget
- Using the REST API filter, including two meta_queries breaks the response for one custom post type
- Are blocks that are converted to patterns no longer filterable through the_content?
- How do I query Pending posts?
- Load More : Admin Ajax 400 Bad request, returning 0