您可以添加短代码属性
修改插件中的短代码回调,使其支持以下参数:
[i20_Sidebar_Widgets高度=“400”宽度=“350”]
将此添加到您的shortcode函数中:
function i20_sidebar_widgets_shortcode($atts) {
$atts = shortcode_atts(
array(
'height' => '',
'width' => '',
),
$atts,
'i20_Sidebar_Widgets'
);
$height = !empty($atts['height']) ? $atts['height'] : get_option('itsw_height_of_i20_sidebar');
$width = !empty($atts['width']) ? $atts['width'] : '100%';
ob_start();
?>
<div class="border-onestop" style="height:<?php echo esc_attr($height); ?>px; width:<?php echo esc_attr($width); ?>;">
<!-- widget content -->
</div>
<?php
return ob_get_clean();
}
add_shortcode('i20_Sidebar_Widgets', 'i20_sidebar_widgets_shortcode');
Then you can use shortcode like:
Category page:
[i20_Sidebar_Widgets height="600" width="100%"]
Tag page:
[i20_Sidebar_Widgets height="500" width="80%"]
Single post page:
[i20_Sidebar_Widgets height="450" width="100%"]
This will not affect each other, because each shortcode instance has its own inline style.