简体   繁体   English

如何在Wordpress中包含jquery,jquery-ui

[英]How to include jquery, jquery-ui in wordpress

How to include jquery, jquery-ui-core and https://www.paytabs.com/theme/express_checkout/js/jquery-1.11.1.min.js in wordpess. 如何在wordpes中包含jquery,jquery-ui-core和https://www.paytabs.com/theme/express_checkout/js/jquery-1.11.1.min.js I get an error "Uncaught TypeError: jQuery(...).UItoTop is not a function". 我收到一个错误“未捕获的TypeError:jQuery(...)。UItoTop不是函数”。 Here's a piece of code: 这是一段代码:

function magikCreta_load_jquery(){
      wp_enqueue_script('jquery');
      wp_enqueue_script('jquery-ui-core');
      wp_enqueue_script('jquery-ui', 'https://www.paytabs.com/theme/express_checkout/js/jquery-1.11.1.min.js', array('jquery-ui-core'));
    }

<?php echo '<script>
            jQuery(document).ready(function($){
                Paytabs("#express_checkout").expresscheckout({
});</script>';

Please go through the belwo code, hope that assists 请通过belwo代码,希望对您有所帮助

add_action('wp_enqueue_scripts', 'my_enqueue_scripts');
function my_enqueue_scripts() 
 {
      //the array with jquery and jquery-ui-core are dependency for your file i.e my-custom.js 
    wp_enqueue_script('my-custom-js', get_stylesheet_directory_uri().'/my-custom.js', array('jquery', 'jquery-ui-core'));  
}

And place your custom code to my-custom.js : 并将您的自定义代码放入my-custom.js

jQuery(document).ready(function($){
                Paytabs("#express_checkout").expresscheckout({
});

The nice way would be to load a separate file. 好的方法是加载一个单独的文件。

add_action('wp_enqueue_scripts', 'so13452_enqueue_scripts');
function so13452_enqueue_scripts() {
    // The array('jquery', 'jquery-ui-core') will force jquery and jquery-ui-core from core to be included
    wp_enqueue_script('name', get_stylesheet_directory_uri().'/file.js', array('jquery', 'jquery-ui-core'));

    // Only include jquery core
    wp_enqueue_script('jquery');

    // Jquery ui core
    wp_enqueue_script('jquery-ui-core');

}

You can also add it inline: 您也可以内联添加:

add_action('wp_head', 'so13453_enqueue_scripts');
function so13453_enqueue_scripts() {
    ?>
        <script>
            //
        </script>
     <?php
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM