我有这样的代码
[mt\\u ptcolumn size=“pricing-3-col”title=“brown”price=“$99”period=“1 domain”button=“Purchase”url=“\\;”]
我想在按钮“”中添加一个短代码,如下所示
[mt\\u ptcolumn size=“pricing-3-col”title=“brown”price=“99美元”period=“1域”button="[another-shortcode]" url=“#”]
但它不起作用。那么,我如何编辑下面的代码才能使其正常工作呢?
if (!function_exists(\'mt_ptcolumn\')) {
function mt_ptcolumn($atts, $content = null) {
extract(shortcode_atts(array(
\'title\' => \'Basic\',
\'price\' => \'$40\',
\'period\' => \'per month\',
\'url\' => \'#\',
\'button\' => \'Buy Now!\'
), $atts));
$ptoutput =\'\';
$ptoutput .= \'<div class="pt-column">\'."\\n";
$ptoutput .= \'<h3>\'.$title.\'</h3>\'."\\n";
$ptoutput .= \'<div id="tab_price" class="pt-cost"><p>\'.$price.\'<span>\'.$period.\'</span></p></div>\'."\\n";
$ptoutput .= \'<div id="tab_btn" class="pt-cost"><a href="\'.$url.\'" class="mt-button large" style="margin-top:25px">\'.$button.\'</a></div>\'."\\n";
$ptoutput .= \'<div class="pt-features">\'."\\n";
$ptoutput .= do_shortcode($content);
$ptoutput .= \'</div>\'."\\n";
$ptoutput .= \'<div class="pt-buynow"><a href="\'.$url.\'" class="mt-button large">\'.$button.\'</a></div>\'."\\n";
$ptoutput .= \'</div>\'."\\n";
return $ptoutput;
}
add_shortcode(\'mt_ptcolumn\', \'mt_ptcolumn\');
}
谢谢你
最合适的回答,由SO网友:fischi 整理而成
你必须执行do_shortcode()
在您的$button
.
$ptoutput .= \'<div class="pt-buynow"><a href="\' . $url . \'" class="mt-button large">\' . do_shrtcode( $button ) . \'</a></div>\' . "\\n";
Be aware of endless recursions!
您还可以检查
$button
如果要强制设置,则将设置为短代码。
if ( !has_shortcode( $button, \'another_shortcode\' ) ) { // Fallbacks to enforce the Shortcode
由于这没有经过测试,您可能需要在中添加短代码的括号
$button
之后,为了确保原来的短代码正常工作,但遗憾的是,我不知道您是否需要这样做。
$button = \'[\' . $button . \']\';