在WordPress中包含并注册Javascript文件函数.php
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在WordPress中包含并注册Javascript文件函数.php相关的知识,希望对你有一定的参考价值。
This code should be added to the functions.php file in the theme's folder. The code will deregister the local copy of jQuery and instead include the google hosted copy. It will also register other scripts.
<?php function my_script_init() { if (!is_admin()) { // deregister local copy of jQuery wp_deregister_script('jquery'); // register google hosted jquery wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js', false, '1.6.1'); wp_enqueue_script('jquery'); // register some other javascript file (just for the sake example) wp_register_script('otherfile', get_bloginfo('stylesheet_directory').'/scripts/jquery.otherFile.js', array('jquery')); wp_enqueue_script('otherfile'); // register another file that requires that the other two files are loaded first wp_register_script('mainjs', get_bloginfo('stylesheet_directory').'/scripts/main.js', array('jquery','otherfile')); wp_enqueue_script('mainjs'); wp_deregister_script( 'l10n' ); } } add_action('init', 'my_script_init');
以上是关于在WordPress中包含并注册Javascript文件函数.php的主要内容,如果未能解决你的问题,请参考以下文章