Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save celticwebdesign/130ea5bf0c252f5904765e76e48431f2 to your computer and use it in GitHub Desktop.
Save celticwebdesign/130ea5bf0c252f5904765e76e48431f2 to your computer and use it in GitHub Desktop.
WordPress - Enqueue script on specific page template
// https://wordpress.stackexchange.com/questions/61244/wp-enqueue-style-on-specific-page-templates
function my_enqueue_stuff() {
global $template;
$template_array = explode('/',$template);
if ( end($template_array) == 'single-recipes.php' ) {
wp_enqueue_script('jspdf', 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.debug.js', array(), '20170816', true );
// http://rawgit.com/MrRio/jsPDF/master/docs/
// A library to generate PDFs in client-side JavaScript.
}
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );
@celticwebdesign
Copy link
Author

I explode the string url in order to obtain the last array value (last segment of the URL).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment