It is not always necessary for all of your scripts and styles to be loaded on every page of your website. In this scenario it is possible to conditionally load certain scripts and styles based on the WordPress page template that is being used.
To conditionally load scripts and styles based on WordPress page template you should wrap a conditional tag around the relevant enqueue tags in
Please see the example below:
In this example the
/my-path/styles.css files would only load on pages that use the
page-custom.php page template.
If you would like to discuss this article or have any other queries regarding its contents please don’t hesitate to contact me.