Wp add_shortcode属性未更改属性值

问题描述 投票:0回答:1

我已经创建了带有属性的简码(在google的帮助下),但是它不会更改属性值。我已经用谷歌搜索了很多这个问题,但是没有找到解决方案。这是我的代码:

function infobox_shortcode( $atts ) {

    $array = shortcode_atts(
        array(
            'Background' => 'rgba(45, 90, 171, 0.1)',
            'Border' => 'rgba(45, 90, 171, 0.5)',
            'Color' => '#2561ea',
        ),
        $atts
    );
        return "<div class='note' style='background-color:{$array['Background']};border-color:{$array['Border']};color:{$array['Color']};'>
                <span class='note-icon'><i class='ti ti-info'></i></span>
                <span class='ml-2'>
                    Want to use this template in Shopify, Wordpress or other platform?
                </span>
            </div>";

}
add_shortcode( 'InfoBox', 'infobox_shortcode' );

而且我在主题的index.php页面中这样称呼它:

<?= do_shortcode('[InfoBox Background="red"]'); ?>

但是它没有更改属性Background的值,我不知道我要去哪里。如果有人帮助我,这将是有帮助的。

php wordpress wordpress-theming shortcode
1个回答
0
投票

这是我的错误,我使用这样的大写字母创建属性

'Background' => 'rgba(45, 90, 171, 0.1)',

但是应该用小写字母,并且现在可以使用。

'background' => 'rgba(45, 90, 171, 0.1)',
© www.soinside.com 2019 - 2024. All rights reserved.