你们中的一些人可能知道,我一直在努力将Javascript加入到我的Wordpress主题中,但我无法让它工作。我得想办法把这件事做完。我会不断更新这个问题,我会编辑,我希望你能与我一起一步一步地完成这个任务!已经几个月了,我仍然无法让它工作,我也不知道为什么!
Step 1:
我想移动标题中的所有脚本调用。php到我的函数中。php。我把一切都转移到我的职能上。php:(updated!)function add_my_javascripts() {
/* If this is the admin area of WordPress, don\'t do anything */
if( is_admin() )
return;
/* Register all of our scripts */
wp_register_script(\'jquerytools\', \'http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js\', array(\'jquery\'));
wp_register_script(\'jquery.form\', get_template_directory_uri() . \'/js/jquery.form.js\', array(\'jquery\'));
wp_register_script(\'sprinkle\', get_template_directory_uri() . \'/js/sprinkle.js\', array(\'jquery\', \'jquery-ui-core\', \'jquery-ui-tabs\'));
wp_register_script(\'custom\', get_template_directory_uri() . \'/js/custom.js\', array(\'jquery\'));
wp_register_script(\'tooltip\', get_template_directory_uri() . \'/js/tooltip.js\', array(\'jquerytools\'));
wp_register_script(\'tooltip\', get_template_directory_uri() . \'/js/sliding_tabs.js\', array(\'jquerytools\'));
wp_register_script(\'contact-form\', get_template_directory_uri() . \'/js/contact-form.js\', array(\'jquery\', \'jquery.form\'));
/* Enqueue the ones that need to be enqueued */
wp_enqueue_script(\'sprinkle\');
wp_enqueue_script(\'custom\');
wp_enqueue_script(\'tooltip\');
wp_enqueue_script(\'sliding_tabs\');
wp_enqueue_script(\'contact-form\');
}
add_action(\'wp_enqueue_scripts\', \'add_my_javascripts\');
这是我的whole function.php 只是为了确保没有其他错误继续干扰wp\\U排队或其他事情:http://pastebin.com/mhCNZbFW此外,我在我的PARENT THEME\'s function.php! 我不使用函数。php for my child主题。我试图在我的标题中调用该操作。php:(UPDATE: Currently NO HOOK at all, also no CALL in my header.php!!)
Result:所有脚本都已正确加载(使用Firebug进行检查),但没有一个脚本真正起作用!只有“custom.js”可以工作(即使没有在header.php中调用操作)。
为什么这不起作用?请帮我解决这个问题,因为它会带来很多问题!
Step2: (已解决)下一步将是为每个jQuery JS提供无冲突包装(这也不起作用)。
我已经尝试了:-停用所有插件(无效)-创建了一个函数。php用于我的子主题,并将上面的代码从父主题的函数中移除。php(结果:错误消息
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, \'get_my_scripts\' was given in /hermes/bosweb25a/b155/ipg.zoomingjapancom/wp-includes/plugin.php on line 405
-尝试了另一个主题(TwentyEleven):同样的问题-我试图在标题中这样称呼它。php(正如在TwentyEleven主题中所做的那样:<?php wp_enqueue_script( \'jquery\', \'jquerytools\', \'jquery-ui-person\', \'jqueryform\', \'sprinkle\', \'custom\', \'tooltip\' ); wp_head(); ?>
</head>
那也不行。。。LATEST NEWS:请参阅更新的功能。上面的php代码。我现在要做很多事情。至于联系人所需的jquery表单。php我刚刚从联系人中取出了直接脚本调用。php并将其放入自己的js文件中,然后用无冲突包装器将其包装,现在一切正常!我唯一担心的是Wordpress现在是否会将其加载到每个页面上,尽管它只在联系人上需要。php??!!
THE ONLY THING THAT IS STILL NOT WORKING is sprinkle.js:可能的原因是,可能与ui选项卡和jquerytools ui选项卡存在冲突。我应该这样做,但不知道该放在哪里:
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript" src="jquery.tools-1.2.6-dev.js"></script>
<!-- must do this before including jquery-ui -->
<script type="text/javascript">
// change name of jquery tools tabs so that jquery UI doesn\'t barf
jQuery.fn.jtTabs = jQuery.fn.tabs;
</script>
<script type="text/javascript" src="jquery-ui-1.8.14.js"></script>
如果您需要任何进一步的信息,请让我知道!这是我的website 供参考。我一个人做不到。请给我一些建议!任何事情都可能有帮助:)提前谢谢!