functions – Enqueue script o style only if a template part is loaded

Question

I have registered some styles and scripts that should be loaded if a template part is loaded in a template file. For ex:

in home.php

<?php get_template_part( 'template-parts/external_links'); ?>

(this template-part is loaded across different template files) therefore, I want to enqueue (a previously registered file in functions.php)

Using template files for example I use:

if(is_page_template('admin.php')){
        wp_enqueue_script( 'unicorn-admin');
    }

Is there a way to enqueue a file when get_template_part( ‘template-parts/external_links’); is used?

0
Alexandro Giles 2 months 2021-09-21T14:50:38-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse