For example, I have two headers
header.twig
и
new-header.twig
I need to validate the header on the page and plug in scripts and styles depending on the header.
Translated with DeepL.com (free version)
I’ve done it like this
// Get the context of the current page
$context = Timber::get_context();
if (isset($context['header_type']) && $context['header_type'] === 'new') {
// This is the new header
// Connect the appropriate styles
wp_enqueue_style('new-header');
wp_enqueue_style('new_post_style');
} else {
// This is the standard header
// Connect standard styles
wp_enqueue_style('google-fonts');
wp_enqueue_style('select2');
wp_enqueue_style('animation-css');
wp_enqueue_style('fancybox-css');
wp_enqueue_style('swiper');
wp_enqueue_style('new-style');
wp_enqueue_style('new-water-heater');
wp_enqueue_style('heat-pump');
// Connect the corresponding scripts
wp_enqueue_script('foundation');
wp_enqueue_script('what-input');
wp_enqueue_script('fancybox-js');
wp_enqueue_script('select2');
wp_enqueue_script('animation-js');
wp_enqueue_script('parallax');
wp_enqueue_script('swiper');
wp_enqueue_script('rebates');
}
But nothing works for me
New contributor
Азат Эрланов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.