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?
- How can I extend the Gutenberg table block transform to allow colspans/rowspans on pasted table elements?
- Shortcode from a widget is wrapped in unwanted element
- How to disable all WordPress emails modularly and programatically?
- Allow Profile HTML for select users
- Search with filters and title
- failed to filter hook `get_terms_defaults`
- Filter list by a unique meta value dilemma
- How to filter a wordpress core function?
- Filter pre_get_posts does not modify Mine/All/Pending
- Can i use multiple ‘the_content’ filters?
- What is the earliest hook to modify post content?
- How to modify only part of a function through the filter
- How can I apply filters in my class that extends Walker_Nav_Menu?
- How should I be using filters and is_single together?
- comment_notification_text filter not working
- WordPress remove_filter not working
- Strange behaviour of REGEX in a WordPress filter (trying to suppress emtpy paragraphs)
- How to make an If Else on Excerpt Filter
- 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
- can’t output gray scaled image I’ve created using add_image_size