简体   繁体   中英

How can I include Jquery in my Wordpress footer?

I want to .load the php script every 10 seconds. The load code is not a problem, but in Wordpress all plugins use their own Jquery libraries, and if I just add the jquery google link:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>

the other plugins will crash.

I have the following code in my footer:

<?php
if ( is_user_logged_in() ) {
include 'completed.php';
}
?>

I want to include a jquery script so I can execute the following code:

<?php
if ( is_user_logged_in() ) { ?>
<div id="completed">
    <script>
    $(function(){
        setInterval(function(){
               $("#completed").load("completed.php");
        }, 10 * 1000);
    });
    </script>
</div>
<?php } ?>

Do you think you can help me out?

Load the jquery from google ajax library in footer

function my_init() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_deregister_script('jquery'); 
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js', false, '1.3.2', true); 
        wp_enqueue_script('jquery');
    }
}
add_action('init', 'my_init');

But why won't you do use the built in jQuery in no-conflict mode so that nothing crashes.

<?php
 if ( is_user_logged_in() ) { ?>
 <div id="completed">
 <script>
   jQuery(function(){
     setInterval(function(){
           jQuery("#completed").load("completed.php");
     }, 10 * 1000);
   });
 </script>
 </div>
<?php } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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