I am converting html5 to wordpress Theme. I want to use custom scroll for wordpress. The code

DEPENDENCIES It's a plugin for the jquery framework, you need to include jquery in your scripts.

I will use

<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>

Will it work just by that What about below code?

  function() {

EXAMPLES 1. Simple mode, it styles document scrollbar (html element prefered):

Where to enter this to make it work?

After enqueuing , do i need it again to add in header.php Explanation will be helpful.

How to use this code?

var seq = 0;

  $(document).ready(function() {    

    $("#mainlogo img").eq(1).hide();
    function goSeq() {
      var nxt = (seq+1)%2;
      $("#mainlogo img").eq(seq).fadeIn(2000);
      $("#mainlogo img").eq(nxt).fadeOut(2000);
      seq = nxt;

        $("#gmbox div").animate({'top':60},1500,"easeOutElastic");

    function trackLink(link, category, action) {
      try {
        _gaq.push(['_trackEvent', 'tracklink' ,'click',link.href ]);
        setTimeout('document.location = "' + link.href + '"', 100)

      try {

  • Your question is very confusing. – s_ha_dum Jan 1 '14 at 15:37
  • have you tried to look at the examples in the codex? – Mark Kaplun Jan 1 '14 at 15:42

wordpress runs jquery in noconflicts mode which means that you either need to write your JS code using the jQuery function call

  function() {

or the following syntax which define $

  function($) {
  • Thanks, I want the JQuery call function in which file . header.php – user44529 Jan 1 '14 at 19:48
  • and mark, What should i do with this javascript – user44529 Jan 2 '14 at 17:13
  • don't understand – Mark Kaplun Jan 3 '14 at 4:43

In WordPress, you could put the script in header too.

But as the best practice. Save your file as script.js and call your script with

<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>

in functions.php

$handle = name, anything you want.

$src = where the file is.

$deps = dependencies, your script depends to jQuery. So load the jQUery first than your code.

$ver = version of your code

$in_footer = default is false, it means your code put in header.

The code for you, put in functions.php

if ( ! function_exists( 'your_enqueue' ) ) :
    function your_enqueue(){
wp_enqueue_script(' name ', get_template_directory_uri(). '/script.js' , array('jquery')), '1.0', false);
add_action('wp_enqueue_scripts', 'your_enqueue');

what I wrote above is one of the best practice to insert a javascript that highly recommended from WordPress team.

Please refer to,

  1. http://codex.wordpress.org/Function_Reference/wp_enqueue_script
  2. http://codex.wordpress.org/Function_Reference/get_template_directory_uri
  • Thanks. but with $(document).ready( function() { $("html").niceScroll(); } ); – user44529 Jan 1 '14 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.