2015-10-14 85 views
0

我想將library添加到wordpress中 所以我已經將所有的CSS和JavaScript庫添加到Wordpress中 現在我必須運行時,下面的函數調用將執行一些Java代碼。

$(document).ready(function(){ 
     if (Modernizr.touch) { 
      // show the close overlay button 
      $(".close-overlay").removeClass("hidden"); 
      // handle the adding of hover class when clicked 
      $(".img").click(function(e){ 
       if (!$(this).hasClass("hover")) { 
        $(this).addClass("hover"); 
       } 
      }); 
      // handle the closing of the overlay 
      $(".close-overlay").click(function(e){ 
       e.preventDefault(); 
       e.stopPropagation(); 
       if ($(this).closest(".img").hasClass("hover")) { 
        $(this).closest(".img").removeClass("hover"); 
       } 
      }); 
     } else { 
      // handle the mouseenter functionality 
      $(".img").mouseenter(function(){ 
       $(this).addClass("hover"); 
      }) 
      // handle the mouseleave functionality 
      .mouseleave(function(){ 
       $(this).removeClass("hover"); 
      }); 
     } 
    }); 

我如何可以添加到我的網頁?

回答

0

你應該在一個文件中添加此代碼,並與wp_enqueue_scripts增加。
function scripts_styles() {

wp_enqueue_script

wp_enqueue_script('script-id', get_template_directory_uri() . '/js/main.js', array('jquery'));

添加CSS添加JavaScript和wp_enqueue_style

wp_enqueue_style('all-theme', get_template_directory_uri() . '/css/style.css.css');
} add_action('wp_enqueue_scripts', 'scripts_styles');

相關問題