I just noticed a weird behavior on a theme I'm working on. If I have a post with just one link or shortcode,
the_excerpt will print that URL or shortcode. But if I have some text in the post, below or above the same link or shortcode,
the_excerpt returns only the text.
Why is this happening? And is there a simple way to remove the links and shortcodes if there is no other content in a post?
The only filters I used on
the_excerpt are the
excerpt_length. Also, in my loop I'm using
-- Later edit --
After exchanging a few comments below it became obvious that I should also include a few examples in this questions to clarify two thinks: 1) the default behavior of
the_excerpt and 2) the case and solution I'm looking for.
Default behavior of
If there is content below or above a shortcode, only the content (text) will be shown by
If there is no content below or above a shortcode that contains an URL, the URL will be shown by
the_excerpt. The same happens if instead of a shortcode thre's an embeddable URL (like a youtube link).
Example: If I have in a post only this shortcode
the excerpt will print only the URL ->
What I would want to do is this: if
the_excerpt displays only an URL, then display 'no content'.