Question

I need a short code the will call the following script and add it where the short code is in the page/post:

<script class="secret-source">
                    jQuery(document).ready(function($) {

                        $('#banner-fade').bjqs({
                            height: 350,
                            width: 980,
                            responsive: true
                        });

                    });
                </script>

The short code can be [end_slider]

Was it helpful?

Solution

You'll have to add the javascript somewhere, and echo it on a shortcode.

Quick example (I just dropped out of PHP, too much work to write echo)

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

Then you'll have to add that somewhere where it's called, a plugin comes to mind, and there you could put this in an external file and use the more proper wp_enqueue_script to add it with jQuery as a depedency

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top