Generating the excerpt is quite a jumble of filters, so it’s difficult to see precisely what is happening, but here is my guess:
WordPress attaches a default filter (see line 148) to get_the_excerpt
, namely wp_trim_excerpt
. As you can see from the latter function’s source code, it starts with getting the content if it gets passed an empty string. Now, if this filter is executed after yours and there are only shortcodes in the post, your filter will pass an empty string and the default filter will simply ignore everything you have done and start generating its own excerpt. So you could try making sure your filter is executed later, by changing its priority:
add_filter ('the_excerpt', 'my_custom_excerpt', 1, 20);
Alternatively, you could remove that filter:
remove_filter('get_the_excerpt', 'wp_trim_excerpt', 10);
Related Posts:
- run shortcode in excerpt of single custom post type
- Auto-generated excerpt with shortcode and read more button/text link
- apply_filters(‘the_content’, $content) vs do_shortcode($content)
- How to get shortcode’s input values inside a filter?
- Filter specific shortcode output?
- Insert Custom HTML After Shortcode
- Is there a way to add another row to the tinyMCE kitchen sink toggle?
- add_filter and changing output captions of image gallery
- Get excerpt from $post->post_content
- How to use the_excerpt in a filter hook?
- How to add attribute to output with wp_video_shortcode add_filter
- add_filter on “the_excerpt” only works when post does not have excerpt
- Search content for shortcodes and get parameters
- Change default settings used by gallery shortcode
- Shortcodes not resolved in AJAX call response
- Ajax, filters and shortcodes
- End excerpt at the end of the sentence
- Format content value from DB outside of WordPress filters
- Use content custom filter for all shortcodes
- get_the_excerpt() with fallback like the_excerpt()
- How to link current user to their author page through shortcodes
- filter title from shortcode
- how to remove filter from wordpress shortcode output
- How do I filter get_the_excerpt() but keep all of its functionality intact?
- Error when overriding only some audio shortcode HTML output
- How to use shortcode attribute in separate function
- 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
- Shortcodes — Using add_action, add_filter in the shortcode
- Access get_the_title() from ‘excerpt_length’ filter
- How to pass variables to custom filter from multiple functions
- How to filter backend post list showing only posts having a shortcode
- Give “Read More” precedence over excerpt() word count
- How do I override the_excerpt so that it will display full content?
- How can I return shortcode output to the top of the content?
- Excerpt is being added above the content, but it should be after it
- apply_filters(‘get_the_content’, $content) + Except
- Filter everything from content except output of a shortcode
- Something is filtering my shortcodes… Can’t figure out what
- Trimming a custom field to a length
- How to use do_shortcode_tag to modify the output of a shortcode?
- Shortcodes within the sidebar text/html widget: How to preserve the raw HTML output of the shortcode?
- How to change dynamically page title according to variable data?
- How can I filter tag_description()?
- WordPress removing slashes from shortcode output
- Adding html banner to posts
- Apply wordpress filter checking category
- How to remove shortcode(s) from WYSIWYG Page editor for Non Admins
- Add Filter – Pass Variable (PHP < 5.3)
- Shortcode / plugin with custom (flexible) output
- Filter Shortcodes when using get_page
- Parse a shortcode differently based on on what it’s nested in
- Need to return shortcode text instead of the output
- add_filter to the_content after apply_filters
- post_orderby filter breaks function
- the_content getting current page content instead specified ID
- Filter Post Title without affecting screen-reader-text
- Override wordpress audio playlist
- Create different flavours of excerpt
- How to wrap pattern-matches from the_content in [wiki]-shortcode tags
- Add Index to Item in WordPress Gallery
- create a shortcode with acf including a filter
- How to take shortcode and content separately from a page?
- Cutting off excerpt with first sentence
- Hide disclaimer from summary excerpts
- Read More in the actual excerpt
- shortcode function outputs multiple anchor tags
- apply_filters to $GLOBALS
- Change shortcode output (filter?)
- is_page_template() doesn’t work with excerpt_length filter
- Is it possible to include the add_filter() function within a shortcode function
- Activate short codes for all post queries?
- Problem with shortcodes in external file
- 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
- How can I display wp_link_pages before a shortcode, if it is used, or display after content?
- Why does using excerpt_more filter change link location?
- hook on the_excerpt
- AAPF Filter group is not in widget section
- filter wptexturize doesn’t work on old posts titles
- Post Type Upload Directory – {post_type}_upload_dir filter
- How to remove a filter that is an anonymous object?
- Custom search fields and AJAX support
- remove_action conditionally for Custom Post Type – not working
- Custom xmlrpc request does not pass parameters?
- add_filter not adding the filter
- Adding to an array & passing it through do_action/apply_filters
- Using “excerpt_more” filter for a specific post type
- wp.getPosts with status = ‘trash’ using node.js
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- using posts_where for meta data on pre_get_posts
- Hook into ‘when user logs in’ [persistent login]
- Filter on widget-title does not work with custom links
- Hide H1 Title using the_title filter
- Can’t get content of all (19) posts – Incomplete Chunked Encoding
- Admin filter/error if post title is too long
- apply_filters to content but ignore shortcodes
- Custom registration field to SQL database