[英]Wordpress do_shortcode with $atts['shortcode'] inside
我只是在嘗試顯示我的簡碼時遇到了這個問題,希望有人能給我一個解決方案:
我的目標:我需要 Visual Composer 中的文本字段,這樣我就可以為每個付款按鈕添加一個唯一的短代碼。
這是我創建的文本字段:
array(
'type' => 'textfield',
'heading' => esc_html__('Shortcode', 'softing'),
'param_name' => 'shortcode',
'edit_field_class' => 'vc_col-sm-4',
),
這是我將插入其中的簡碼: [purchase_link id="3839" text="Add To Cart" style="button" color="orange"]
現在我正在嘗試顯示短代碼:
$out .= '<div class="pricing-box-shortcode">'.'<div class="#pricing-box-shortcode">'.do_shortcode($atts['shortcode']).'</div>'.'</div>';
這是結果和我的實際問題:截圖
我注意到如果我不使用$atts['shortcode']而只是粘貼我的簡碼 - 它可以工作。
do_shortcode([purchase_link id="3839" text="Add To Cart" style="button" color="orange"])
任何解決方案或線索將不勝感激!
如果您想為按鈕添加簡碼,您也可以使用下面的代碼,因為它也可以用作簡碼,您也可以顯示按鈕
function button_shortcode( $atts ) {
return "<input type='button' id='3839' class='button_class_name' name='button_name' value='yes'>";
}
add_shortcode( "purchase_link", "button_shortcode" );
您可以在頁面中使用上述簡碼:
<?php echo do_shortcode('[purchase_link]'); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.