内含$ atts ['shortcode']的Wordpress do_shortcode

时间:2019-10-03 02:36:36

标签: php wordpress wordpress-shortcode

我只是在尝试显示我的简码时遇到问题,希望任何人都可以给我解决方案:

我的目标:我在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 =“添加到购物车” style =“ button” color =“ orange”]

现在,我尝试使用以下方式显示简码:

$out .= '<div class="pricing-box-shortcode">'.'<div class="#pricing-box-shortcode">'.do_shortcode($atts['shortcode']).'</div>'.'</div>';

这是结果和我的实际问题: Screenshot

我注意到,如果我不使用 $ atts ['shortcode'] ,而是粘贴我的短代码-可以。

do_shortcode([purchase_link id="3839" text="Add To Cart" style="button" color="orange"])

任何解决方案或线索将不胜感激!

1 个答案:

答案 0 :(得分:0)

如果要为按钮添加简码,也可以使用以下代码,因为它也可以用作简码,并且还可以显示按钮

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]'); ?>