简体   繁体   中英

How to load plugin js files to custom wordpress theme?

I'm making a WordPress theme, I'm new to WordPress but know a lot about HTML, CSS, JavaScript, jQuery and PHP.

The problem is the theme I'm creating is not loading plugin js files.

Here the my header code:

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

i'm loading jquery manually but i tried to load jquery with wordpress functions.

also tried this code,

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');
}

but didn't working. i have tried many plugins, but just js files of plugins not loading so no plugins working.

I have tried metaslider plugin and Easy Image Gallery plugin. both works in Wordpress default theme but not in mine, because of js file.

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

Can you try add it on function.php, for example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM