admin管理员组文章数量:1122846
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=""][/audio]
, 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'.
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'.
1 Answer
Reset to default 0when outputting you can use strip_shortcodes( $content )
which will remove all shortcode tags from the given content.
本文标签: theme developmentFilter URL and shortcodes from theexcerpt
版权声明:本文标题:theme development - Filter URL and shortcodes from the_excerpt 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736297687a1930064.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
regex
to remove the URLs and then also astrip_shortcodes
... – George Grigorita Commented Dec 18, 2014 at 12:35[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. – cybmeta Commented Dec 18, 2014 at 18:43