因此,如果我在functions.php中的子文件夹根目录中使用以下内容,它的工作原理是:
add_action( 'wp_enqueue_scripts', 'register_my_scripts');
add_action( 'wp_enqueue_scripts', 'checkboxCheckAll');
//register_scripts
function register_my_scripts(){
wp_register_script('checkboxCheckAll', get_stylesheet_directory_uri().'/Lib/dynamic-table/jsScripts/checkboxCheckAll.js');
}
//enqueue_scripts
function enqueue_my_scripts(){
wp_enqueue_script('checkboxCheckAll');
}现在,我有了一个具有以下代码的自定义页面:
<?php /* Template Name: vagter-flex */ ?>
<?php get_header(); ?>
<div class="x-main full" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-wrap">
<?php x_get_view( 'global', '_content', 'the-content' ); ?>
<?php require('Lib/dynamic-table/functions.php');?>
</div>
</article>
<?php endwhile; ?>
</div>
<?php get_footer(); ?>现在,这个页面还加载了一个名为functions.php的文件,如果我尝试用与上面的代码相同的代码对脚本进行队列,就不会显示错误,什么也不会发生。
为了表明是的,当我尝试使用脚本时,我在自定义页面上。
发布于 2016-06-12 11:20:38
这不是functions.php在WordPress中的工作方式。
在默认情况下,只要主题被激活,主题根目录中的functions.php就会加载到WordPress环境中。它被用作插件,将主题的特性和功能添加到WordPress中。您应该查看主题功能和包括和javascript以获得更多信息。
此外,wp_排队_脚本钩子是在到达_标头()中触发的,在require('Lib/dynamic-table/functions.php')之前就会发生这种情况。
您可以通过require('Lib/dynamic-table/functions.php')在主题根目录中的functions.php中修复这个问题。
https://wordpress.stackexchange.com/questions/229499
复制相似问题