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
CodePudding user response:
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 the wp_head()
is called in your templates or template parts, as well as the the wp_footer()
.
The wp_footer()
function is going to be required namely if you're using the $in_footer
boolean argument for your wp_enqueue_script()
function calls!