我有一个插件,它有一个下面的自定义页面模板。该模板需要 jQuery。我有一个变量 $link_to_js 喜欢 google 库,但我希望它将它链接到 WordPress 内部 jQuery 库?
<?php
/*
Template Name: Checkout Template
*/
// Need to replace below with WordPress library???
//$link_to_js = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="<?php echo $link_to_css; ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo $link_to_js; ?>"></script>
</head>
<body>
<div id="authnet_container"><!--CONTAINER START-->
</div><!--FOOTER END-->
</body>
</html>
我在主插件文件中添加了以下代码,但它没有添加?
function my_init() {
if (!is_admin()) {
wp_enqueue_script('jquery');
}
}
add_action('init', 'my_init');
请建议将 jQuery 库添加到自定义插件页面模板的最佳方法?谢谢
你应该包括<?php wp_head(); ?>
and <?php wp_footer(); ?>
就在之前</head>
and </body>
分别。
除其他外,这些函数还包括已排队的脚本和样式。
参考:
- http://codex.wordpress.org/Function_Reference/wp_head
- http://codex.wordpress.org/Function_Reference/wp_footer
至少加上<?php do_action("wp_enqueue_scripts"); ?>
因为这将输出所有排队的脚本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)