• Resolved WH646

    (@wh646)


    I’m developing a theme using bootstrap and underscores, and I’m trying to include the toggling sidebar from StartBootstrap.

    The issue is that my sidebar is not toggling on and off. See here: https://www.wejazzjune.com/sidebar-page/

    I believe it’s not toggling because I am not including the relevant javascript properly.

    This is the script:

    
       
        $("#menu-toggle").click(function(e) {
            e.preventDefault();
            $("#wrapper").toggleClass("toggled");
        });
      
    

    I’ve included that script verbatim in a file called shove.js. I’ve enqueued shove.js via functions.php with this line of code:

    
    
    wp_enqueue_script( 'shove', get_template_directory_uri() . '/js/shove.js', array( 'jquery' ), '1.0.0', true );
    
    

    But it’s not working. I’m sure I’m doing something wrong here.

    The syntax of my javascript file may be wrong or incomplete, or the enqueue code could be wrong or imcomplete, I think. Also, do I need to include jquery.js in my js folder (I’ve done so), or is that redundant / causing a problem?

    Really lost here, so any help is appreciated!

    • This topic was modified 8 years, 1 month ago by WH646.
    • This topic was modified 8 years, 1 month ago by WH646.
    • This topic was modified 8 years, 1 month ago by WH646. Reason: Just trying to make this as clear as possible
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    Thread Starter WH646

    (@wh646)

    Thanks for the reply. I’m familiar with the codex, and I’ve tried the methods outlined there. As I said, I’m enqueuing the script that I created, but I’m looking for some help troubleshooting the js file itself or the enqueue code, both of which are included in my original post.

    Any help would be appreciated.

    • This reply was modified 8 years, 1 month ago by WH646.
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    When I need to debug JS, I use a lot of console.log()statements so I can see where it’s going wrong.

    Also, remember that WP uses jQuery in no-conflict mode so you need to use jQuery(something) instead of $(something)

    Thread Starter WH646

    (@wh646)

    Huzzah! I needed to change the $ to jQuery.

    Thank you so much for your help, @sterndata.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How/where to include javascript for toggling sidebar’ is closed to new replies.