更改Jquery插件的Wordpress Shortcode中的宽度和高度

时间:2014-01-22 01:07:15

标签: jquery wordpress function plugins shortcode

我正在使用以下短代码来调用我的插件:[end_slider]

这是我的函数文件中的代码:

function slider_func() {
 ?>
    <script>
        jQuery(document).ready(function($) {
               $('#banner-fade').bjqs({
                     height: 350,
                     width: 980,
                     responsive: true
               });
         });
    </script>
  <?php
}

add_shortcode( 'end_slider', 'slider_func' );

如何创建一个可以调整短代码中插件宽度和高度的函数?

短代码看起来像这样:[end_slider width =“980”height =“350”]

1 个答案:

答案 0 :(得分:1)

根据WordPress Shortcode API documentation,第一个参数可用于接受短代码属性。

您可以像这样重新配置您的功能:

function slider_func( $atts ) {
    extract( shortcode_atts( array(
        'width' => '600', // default width
        'height' => '400', // default height
    ), $atts ) );
    ?>
    <script>
        jQuery(document).ready(function($) {
               $('#banner-fade').bjqs({
                     height: <?php echo (int) $height; ?>,
                     width: <?php echo (int) $width; ?>,
                     responsive: true
               });
         });
    </script>
    <?php
}