WordPress-自定义模板未加载CSS,JS和Head Tag为空
使用template_include
挂钩将自定义模板分配给query_var
后
add_action( 'template_include', function( $template ) {
if ( (get_query_var( 'checklist_slug' ) == false || get_query_var( 'checklist_slug' ) == '') && (get_query_var( 'checklist_action' ) == false || get_query_var( 'checklist_action' ) == '')) {
return $template;
}
return get_template_directory() . '/includes/checklist_edit.php';
});
,
function uxwithmarwan_files() {
wp_enqueue_script('main-university-js', get_theme_file_uri('/build/index.js'), array('jquery'), '1.0', true);
wp_enqueue_style('custom-google-fonts', '//fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700');
wp_enqueue_style('university_main_styles', get_theme_file_uri('/build/style-index.css'));
wp_enqueue_script('font-awesome', 'https://kit.fontawesome.com/5d2df7d4f7.js');
if ( is_page_template('includes/checklist_create.php') ) {
wp_enqueue_script('main-university-js', get_theme_file_uri('/build/index.js'), array('jquery'), '1.0', true);
wp_enqueue_style('custom-google-fonts', '//fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700');
wp_enqueue_style('university_main_styles', get_theme_file_uri('/build/style-index.css'));
wp_enqueue_script('font-awesome', 'https://kit.fontawesome.com/5d2df7d4f7.js');
}
if ( is_page_template('includes/checklist_edit.php') ) {
wp_enqueue_script('main-university-js', get_theme_file_uri('/build/index.js'), array('jquery'), '1.0', true);
wp_enqueue_style('custom-google-fonts', '//fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700');
wp_enqueue_style('university_main_styles', get_theme_file_uri('/build/style-index.css'));
wp_enqueue_script('font-awesome', 'https://kit.fontawesome.com/5d2df7d4f7.js');
}
}
add_action('wp_enqueue_scripts', 'uxwithmarwan_files');
我有问题如您在这里看到的,模板没有加载任何文件 已加载源的图像 < head>
标签是完全空的 空头标签的图像
I have a problem after using template_include
hook to assign a custom template to query_var
add_action( 'template_include', function( $template ) {
if ( (get_query_var( 'checklist_slug' ) == false || get_query_var( 'checklist_slug' ) == '') && (get_query_var( 'checklist_action' ) == false || get_query_var( 'checklist_action' ) == '')) {
return $template;
}
return get_template_directory() . '/includes/checklist_edit.php';
});
even when I use is_page_template
to enqueue the scripts and stylesheets it's not working
function uxwithmarwan_files() {
wp_enqueue_script('main-university-js', get_theme_file_uri('/build/index.js'), array('jquery'), '1.0', true);
wp_enqueue_style('custom-google-fonts', '//fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700');
wp_enqueue_style('university_main_styles', get_theme_file_uri('/build/style-index.css'));
wp_enqueue_script('font-awesome', 'https://kit.fontawesome.com/5d2df7d4f7.js');
if ( is_page_template('includes/checklist_create.php') ) {
wp_enqueue_script('main-university-js', get_theme_file_uri('/build/index.js'), array('jquery'), '1.0', true);
wp_enqueue_style('custom-google-fonts', '//fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700');
wp_enqueue_style('university_main_styles', get_theme_file_uri('/build/style-index.css'));
wp_enqueue_script('font-awesome', 'https://kit.fontawesome.com/5d2df7d4f7.js');
}
if ( is_page_template('includes/checklist_edit.php') ) {
wp_enqueue_script('main-university-js', get_theme_file_uri('/build/index.js'), array('jquery'), '1.0', true);
wp_enqueue_style('custom-google-fonts', '//fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700');
wp_enqueue_style('university_main_styles', get_theme_file_uri('/build/style-index.css'));
wp_enqueue_script('font-awesome', 'https://kit.fontawesome.com/5d2df7d4f7.js');
}
}
add_action('wp_enqueue_scripts', 'uxwithmarwan_files');
as you see here the template doesn't load any files except the index
image of loaded sources
and <head>
tag is totally empty
image of empty head tag
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
wp_enqueue_scripts
自动将代码删除到网站的“标题”或“页脚”中,您需要确保wp_head()
在您的模板或模板零件中调用,以及wp_footer()
。wp_footer()
函数,如果您使用$ in_footer
代码> 功能调用!When using the
wp_enqueue_scripts
hook (or any others that automatically drop code into the "header" or "footer" of the site, you'll need to make sure that thewp_head()
is called in your templates or template parts, as well as the thewp_footer()
.The
wp_footer()
function is going to be required namely if you're using the$in_footer
boolean argument for yourwp_enqueue_script()
function calls!