我有以下几点Post - Excerpt:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sagittis augue sed orci efficitur convallis at sit amet lectus. [my-short-code]
我的
functions.php
文件:
function getMyShortCode_func() {
echo \'<div class="abc">Hello world.</div>\';
} // end getMyShortCode_func()
add_filter(\'the_excerpt\', \'shortcode_unautop\'); // prevents shortcodes from being auto wrapped in <p> tags
add_filter(\'the_excerpt\', \'do_shortcode\'); // enables shortcodes to be used in excerpts
add_filter(\'get_the_excerpt\', \'shortcode_unautop\'); // prevents shortcodes from being auto wrapped in <p> tags
add_filter(\'get_the_excerpt\', \'do_shortcode\'); // enables shortcodes to be used in excerpts
add_shortcode(\'my-short-code\', \'getMyShortCode_func\');
问题是我
shortcode 内容显示在
excerpt 当我需要出现在
flow of the document:
<div id="myExcerpt">
<span class="postTitleFormat"><a href="http://example.com/this-permalink/">Post Title</a></span>
<div class="abc">Hello world.</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sagittis augue sed orci efficitur convallis at sit amet lectus.</div>
</div>
Definition of Terms:
“文档流”-文档流或文档流是元素在web文档中出现的顺序。例如,每当没有css定位样式改变文档中元素的正常流动时,元素的流动顺序就会模仿它们在web文档中的显示顺序。在这个问题中,没有改变文档元素流的css样式定义。
最合适的回答,由SO网友:cybmeta 整理而成
Shortcode的回调应该返回字符串,而不是回显它。
function getMyShortCode_func() {
return \'<div class="abc">Hello world.</div>\';
}