【问题标题】:How to load plugin js files to custom wordpress theme?如何将插件 js 文件加载到自定义 wordpress 主题?
【发布时间】:2014-03-29 22:50:31
【问题描述】:

我正在制作一个 WordPress 主题,我是 WordPress 新手,但对 HTML、CSS、JavaScript、jQuery 和 PHP 了解很多。

问题是我创建的主题没有加载插件 js 文件。

这里是我的标头代码:

<!DOCTYPE HTML>
<html>
<head>
<title>
            <?php 
                wp_title('|','true','right');
                bloginfo('name');
            ?>
            <meta charset="<?php bloginfo( 'charset' ); ?>">
            <meta name="viewport" content="width=device-width">

        </title>
        <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
        <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('template_url')?>/css/reset.css" />
        <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('template_url')?>/css/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('template_url')?>/css/grid.css" />
        <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('template_url')?>/style.css" />

        <script type="text/javascript" src="<?php echo bloginfo('template_url')?>/js/jquery.js"></script>
        <script type="text/javascript" src="<?php echo bloginfo('template_url')?>/js/bootstrap.min.js"></script>

        <?php
            wp_head();
        ?>
    </head>
    <body>
        <div class="container">
            <div class="main-nav row" id="show-nav">
                <a href="javascript:;">Navigation</a>
            </div>
            <div class="main-nav row" id="close-nav">
                <a href="javascript:;">Close Navigation</a>
            </div>
            <div class="row nav-bar">
                <?php

                    wp_nav_menu(array('container_class'=>'main-nav','container'=>'nav'));

                ?>
            </div>

我正在手动加载 jquery,但我尝试使用 wordpress 函数加载 jquery。

也试过这个代码,

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');
}

但没有工作。我尝试了很多插件,但只是插件的 js 文件没有加载,所以没有插件工作。

我尝试过 metaslider 插件和 Easy Image Gallery 插件。由于 js 文件,两者都适用于 Wordpress 默认主题,但不适用于我的主题。

【问题讨论】:

标签: javascript wordpress wordpress-theming


【解决方案1】:

在关闭 body 标签之前不包含 wp_footer 函数,它与 wp_footer 函数一起使用。

【讨论】:

    【解决方案2】:

    你能不能尝试在function.php中添加它,例如:

    wp_register_script('jquery-ui', get_template_directory_uri().'/js/jquery-ui.js');
    wp_enqueue_script('jquery-ui');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      相关资源
      最近更新 更多