How to setup jQuery cookie plugin in wordpress?

2019-09-06 16:33发布

Is the same as installing any other wordpress plugins?

3条回答
在下西门庆
2楼-- · 2019-09-06 16:45

I'd supplement saibot's answer by saying that, instead of a raw <script>...</script> block, you should use wp_enqueue_script() also when including the plugin script:

<?php wp_enqueue_script("jquery-cookie", get_bloginfo('template_url').'/jquery.cookie.js', array(), '0'); ?>
查看更多
Ridiculous、
3楼-- · 2019-09-06 16:54

And to make sure you're including jQuery, i'd supplement to Jani's answer:

<?php wp_enqueue_script("jquery-cookie", get_stylesheet_directory_uri().'/path/to/jquery.cookie.js', array( 'jquery' ), '0'); ?>

get_stylesheet_directory_uri() would be just in case your script is located in a child-theme

Old thread i know, just wanted to share as it got me stuck for some time... until i added that 'jquery' in the array.

查看更多
我只想做你的唯一
4楼-- · 2019-09-06 16:55

Not really, you kind of have to go through the back door a little.

First off, make sure you're including jQuery the 'right' way (WP includes a copy):

 <?php wp_enqueue_script("jquery"); ?>

In the header, include the plugin script the way you normally would, eg,

 <script type='text/javascript' src='source/script.js'></script>

And then when you are writing your script, make sure it's in no-conflict mode:

 (function($){
    $(document).ready(function(){
       //Scripts go in here!
    });
 })(jQuery);

And then stick the actual script inside the jQuery no-conflict wrapper.

Hope this helps.

查看更多
登录 后发表回答