Pregunta

Slightly difficult to explain question, but I am trying to use the jQuery UI with a wordpress theme I am creating. I have linked to the jQuery UI in my head, and jquery.js is already linked to from wordpress includes - however with this setup my jQuery UI elements don't work. They only work when I manually add in a link to jQuery.js - even if it's the same version. See my code below:

<!--wp head -->
<link rel="alternate" type="application/rss+xml" title="Template - Fox &raquo; Test Comments Feed" href="http://www.skizzar.com/template-fox/test/feed/" />
<link rel='stylesheet' id='style-css'  href='http://www.skizzar.com/template-fox/wp-content/themes/fox/style.css?ver=3.9' type='text/css' media='all' />
<script type='text/javascript' src='http://www.skizzar.com/template-fox/wp-includes/js/jquery/jquery.js?ver=1.11.0'></script>
<script type='text/javascript' src='http://www.skizzar.com/template-fox/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.skizzar.com/template-fox/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://www.skizzar.com/template-fox/wp-includes/wlwmanifest.xml" /> 
<link rel='prev' title='Features' href='http://www.skizzar.com/template-fox/features/' />

<!--end wp head -->

<script src="//code.jquery.com/jquery-1.11.0.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
    $(function() {
    $( ".accordion" ).accordion();
    });
</script>

This is the only way I can get my jQuery UI elements to work - but you'll notice that jQuery.js is referenced twice - once in the wp-head and once manually just below it.

When I take my manual edition away, it doesn't work - why is this, and how do I get around it so I'm not including it twice??

¿Fue útil?

Solución

You can replace default jQuery version with CDN link by using this code in your functions.php:

function jquery_cdn() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', 'http://code.jquery.com/jquery-1.11.0.js', false, '1.11.0');
    wp_register_script('jquery-ui', 'http://code.jquery.com/ui/1.10.4/jquery-ui.js', false, '1.10.4');

    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-ui');
}
add_action('init', 'jquery_cdn');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top