I am having trouble loading the script conditionally in my plugin.
I have a DataTables page and want to load datatables scripts only for that page. So I made a page template called datatables-template.php
and loading dynamically so can set the template in page attribute.
The template path is
my-plugin/public/templates/datatables-template.php
So far so all is working fine. However, when I try to load script explicit fore that template using is_page_template()
When I have checked with get_page_template()
that returning theme current page template which is page.php
in my case.
Note: is_page
working fine, of course, since it will check the current page, that would work. I have also checked my path using file_exists
and that returns true. That means I am giving a correct path for the template. So no idea how to check it.
Additionally: I have tried with global $template
which returns the correct plugin template but that doesn't work in conditional check in my plugin file.
global $template;
if('datatables-template.php' == $template){
//load script
}
Question: How can I check if the page has set the specific page template in page attributes, in my case datatables-template.php
and load script explicit for that page?