您好,我正在尝试将jquery启用到我的wordpress网站。到目前为止,我在互联网上搜索了一些有用的东西,但没有任何帮助。
这是我的jquery脚本
jQuery(document).ready(function($){
alert(\'test\');
});
这就是我的函数php中的内容
<?php
add_action( \'wp_enqueue_scripts\', \'add_my_script\' );
function add_my_script() {
wp_enqueue_script(
\'jquerydemo\', // name your script so that you can attach other scripts and de-register, etc.
get_template_directory_uri() . \'/js/jquerdemo.js\', // this is the location of your script file
array(\'jquery\') // this array lists the scripts upon which your script depends
);
}
?>
这是我的另一个文件头。php
<html>
<head>
<?php
wp_head();
?>
<title>Stumble</title>
<link rel="stylesheet" href="<?php bloginfo(\'stylesheet_url\')?>">
</head>
<body>
<div id="wrapper">
<header class="site-header">
<h1>HEADER</h1>
<div id="dropDownButton">
</div>
<nav class="site-nav col-12 col-m-12">
<?php wp_nav_menu( $args);?>
</nav>
</header>
<?php
$args = array(
\'theme_location\' => \'primary\'
);
?>
索引。php
<?php get_header();?>
<div id="main">
<div id="content">
<h1>Main Area</h1>
<?php if (have_posts() ) : while (have_posts() ) : the_post();?>
<h1><?php the_title(); ?></h1>
<?php if (is_single()){
echo "<h4>Posted on " ;the_time(\'Y,j,F\'); echo"</h4>";
} ?>
<p><?php the_content(_(\'(more...)\')) ?></p>
<hr> <?php endwhile; else: ?>
<p><?php _e(\'Sorry, no posts matched your criteria.\') ?></p>
<?php endif; ?>
<div class="nav-previous alignleft"><?php next_posts_link( \'Older posts\' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( \'Newer posts\' ); ?></div>
</div>
<div id="delimiter">
</div>
<?php get_footer(); ?>
页脚。php
<div id="footer">
<?php
wp_footer();
?>
<h1>FOOTER</h1>
</div>
</div>
</body>
<html>