Support » Fixing WordPress » Where do I put this little js snippet?

  • Resolved PODxt


    Hi, I would like to manually insert a js slideshow into my wordpress site. I’m using this one:

    – I downloaded the script as is,
    – created a custom css file for the slider,
    – triggered them with the functions.php file using

    function theme_name_scripts() {
    	wp_enqueue_style( 'unslider', get_stylesheet_directory_uri() . '/js/unslider.css' );
    	wp_enqueue_script( 'unslider', get_stylesheet_directory_uri() . '/js/unslider.js', array( 'jquery' ), '',  true );
    add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

    And for the final step on their website (4. Plug it all together), there’s the following code I don’t even know what to do with it

    $(function() {

    So my question is, where do I put this code?

Viewing 6 replies - 1 through 6 (of 6 total)
  • C W (VYSO)


    Encase it in <script></script tags like so:

    $(function() {

    And add it to the footer, just before the closing </body> tag. I don’t know what your setup is like, but you may need to change it to this in order to make it work:

    jQuery(function() {

    (The reason for this is explained here.)

    Moderator Jose Castaneda



    Two ways I can think of.

    1. Create a new JS file and enqueue it in the footer.

    2. Create a PHP function to hook to wp_footer. It would look a little like:

    add_action( 'wp_footer', 'my_js' );
    function my_js(){ ?>
    jQuery( function() {
      jQuery( '.banner' ) .unslider();
    <?php } // end my_js

    Thanks for looking into it, I tried what you suggested with no luck. Here’s my testing page:

    When I look at the source code, everything seems to be loaded (the custom css, and the js at the footer), no clue what’s going wrong here.

    Moderator Andrew Nevins


    Forum moderator

    This is your banner element:

    <div id="banner">

    C W (VYSO)


    You need to change

    jQuery( '.banner' ).unslider();


    jQuery( '#banner' ).unslider();

    Thanks guys

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Where do I put this little js snippet?’ is closed to new replies.