0
我试图在短代码函数中使用do_shortcode
。问题是,当我在我的页面上使用[terms_and_conditions]
时,它不解析do_shortcode
,我看到[MM_Form_Field type='custom' id='1' isRequired='true' class='']
。它没有被执行。do_shortcode不解析里面的短代码
这是我的函数看起来像:
function terms_and_conditions($atts) {
// Variables
$terms = get_field('terms_content', 'options');
$checkbox = get_field('terms_checkbox_msg', 'options');
// $smarttag = get_field('terms_smarttag', 'options');
$smarttag = do_shortcode(get_field('terms_smarttag', 'options'));
var_dump($smarttag);
$html_out = '';
$html_out .= '<section id="terms">';
$html_out .= '<div class="terms-content-wrapper">';
$html_out .= $terms;
$html_out .= '</div>'; // end terms-content-wrapper
$html_out .= '<div class="terms-checkbox-wrapper">';
$html_out .= '<div class="terms-checkbox">';
$html_out .= do_shortcode($smarttag);
$html_out .= '<p>' . $checkbox . '</p>';
$html_out .= '</div>'; // end terms-checkbox
$html_out .= '</div>'; // end terms-content-wrapper
$html_out .= '</section>'; // end tip-wrapper
return $html_out;
}
add_shortcode('terms_and_conditions', 'terms_and_conditions');
get_field('terms_smarttag','options')'准确返回什么?另外,你在做一些奇怪的短代码魔术或者在do_shortcode的返回值上运行do_shortcode是一个错误吗? – janh
@janh有人告诉我,在这种情况下,我需要运行'do_shortcode'两次。我认为这也是不正确的,我把它命名为'$ html_out。= $ smarttag;'。 'get_field'返回[MM_Form_Field type ='custom'id ='1'isRequired ='true'class ='']。 –
get_field('terms_smarttag','options')'的内容是什么?我不认为你需要两次运行do-shortcode。可能要考虑嵌套它们:''[shortcode_a] [shortcode_b] [/ shortcode_a]' – admcfajn