创建短代码的基础非常简单。您只需创建一个函数,该函数返回要以字符串形式输出的代码,并注册该函数:
function wpse_143641_homebox_shortcode( $atts ) {
return <<<HOMEBOX
<div class="homebx01 clearfix ani-1">
<div class="homebxhead clearfix">
<div class="bxicon homebxicon01"></div>
<div class="bxheadtxt">Category name</strong></div>
</div>
<div class="cl"></div>
<div class="homebxbody clearfix">
<ul class="bxulsty">
<li class="clearfix"><span></span> <strong>Category Description</strong></li>
</ul>
</div>
<div class="cl"></div>
<a class="morebt clearfix" href="#">Link to particular Categories post.</a>
</div>
<div class="homebx01 clearfix ani-1">
<div class="homebxhead clearfix">
<div class="bxicon homebxicon01"></div>
<div class="bxheadtxt">Category name</strong></div>
</div>
<div class="cl"></div>
<div class="homebxbody clearfix">
<ul class="bxulsty">
<li class="clearfix"><span></span> <strong>Category Description</strong></li>
</ul>
</div>
<div class="cl"></div>
<a class="morebt clearfix" href="#">Link to particular Categories post.</a>
</div>
<div class="homebx01 clearfix ani-1">
<div class="homebxhead clearfix">
<div class="bxicon homebxicon01"></div>
<div class="bxheadtxt">Category name</strong></div>
</div>
<div class="cl"></div>
<div class="homebxbody clearfix">
<ul class="bxulsty">
<li class="clearfix"><span></span> <strong>Category Description</strong></li>
</ul>
</div>
<div class="cl"></div>
<a class="morebt clearfix" href="#">Link to particular Categories post.</a>
</div>
HOMEBOX;
}
add_shortcode( \'homebox\', \'wpse_143641_homebox_shortcode\' );
有关如何接受aguments的更多示例和详细信息,请参阅
Shortcode_API 法典文件。