将WordPress jQuery添加到cutom页面模板 [英] Add WordPress jQuery to cutom page template

查看:126
本文介绍了将WordPress jQuery添加到cutom页面模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插件,它有一个下面的自定义页面模板。这个模板需要jQuery。我有一个变量$ link_to_js喜欢google库但是我希望它将它链接到WordPress内部jQuery库?

I have a plugin and it has a below custom page template. This template requires jQuery. I've a variable $link_to_js liked to google library but I want it to link it to the WordPress internal jQuery library?

 <?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>

我在主插件文件中添加了以下代码,但它没有添加?

I've added below code in main plugin file but it does not add?

function my_init() {
    if (!is_admin()) {
        wp_enqueue_script('jquery');
    }
}
add_action('init', 'my_init');

请建议将jQuery库添加到自定义插件页面模板的最佳方法?谢谢

Please advice the best way to add jQuery library to the custom plugin page template? Thanks

推荐答案

你应该包括<?php wp_head(); ?> <?php wp_footer(); ?> 分别在< / head> < / body> 之前。

You should include <?php wp_head(); ?> and <?php wp_footer(); ?> immediately before </head> and </body> respectively.

除其他外,这些函数包括已排队的脚本和样式。

These functions are what, among other things, include scripts and styles that have been queued.

参考文献:

  • http://codex.wordpress.org/Function_Reference/wp_head
  • http://codex.wordpress.org/Function_Reference/wp_footer

至少添加<?php do_action(wp_enqueue_scripts); ?> 因为它将输出所有排队的脚本。

At the very least add <?php do_action("wp_enqueue_scripts"); ?> as that will output all the queued scripts.

这篇关于将WordPress jQuery添加到cutom页面模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆