Created
August 18, 2017 08:36
-
-
Save celticwebdesign/130ea5bf0c252f5904765e76e48431f2 to your computer and use it in GitHub Desktop.
WordPress - Enqueue script on specific page template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' ); |
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
Can you explain why you explode and use the last array index?