I have created a shortcode with attributes (with the help of google), but It does not changing the attributes value. I have googled this issue a lot but didn’t find solution.
Here is my code:
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' );
And I am calling it in my theme’s index.php page like this:
<?= do_shortcode('[InfoBox Background="red"]'); ?>
But it’s not changing the value of attribute Background
, I don’t know where i am going wrong. It’ll be helpful If you people help me.
4
Answers
It was my mistake, I was creating attributes with Capital letter like this
But it should be in small letters, and it worked now.
attribute will be small letters.
This works for me great.