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_more
and excerpt_length
. Also, in my loop I'm using the_excerpt();
.
-- 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 the_excerpt
:
If there is content below or above a shortcode, only the content (text) will be shown by
the_excerpt
.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 [audio mp3="http://path.to.file"][/audio]
, the excerpt
will print only the URL -> http://path.to.file
.
What I would want to do is this: if the_excerpt
displays only an URL, then display 'no content'.
regex
to remove the URLs and then also astrip_shortcodes
...[shortcode]http://someurl.com[/shortcode]
, the auto generated excerpt should print empty string, that is nothing. If you have "Some text [shortcode]someurl.com[/shortcode]", then the auto generated excerpt should print only "Some text". You should post the actual code you are using, include any excerpt filter, content filter and the shortcode code. If you have only a link, the autogenerated excerpt should print the anchor text of the link.