Add The following code (in your theme’s functions.php) will register your script, and set jQuery as a dependency. So when you enqueue it, jQuery will also be enqueued.
function my_scripts_method() {
// register your script location, dependencies and version
wp_register_script('my_custom_script',
get_template_directory_uri() . '/js/custom_script.js',
array('jquery'),
'1.0' );
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
You can then enqueue your script one of two ways. In your theme’s functions.php you can use the template_include filter the get the template being used using is_page_template()
function my_load_script_for_template( $template ){
if(is_page_template('my-template.php'))
wp_enqueue_script('my_custom_script');
return $template;
}
add_filter( 'template_include', 'my_load_script_for_template', 1000 );
Related Posts:
- Shortcode button dosent work for all posts. Work for first post only
- Override Plugin Script Fucnction in WordPress
- Redirect to another page using contact form 7? [closed]
- get specific value of a array | PHP
- How to get specific string/value from an array? php [closed]
- Call javascript functions from each page
- How to add specific script to WordPress webpage that will working with user input and databases
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- Disqus comments count taking long to update
- How to tweak a plugin without preventing it from updating
- Adding a script & php to functions.php
- Plugin update error message
- How to handel multiple checkbox field in the admin settings page with Settings API
- wp_insert_user – how to send verification email before logging in
- Is the WordPress HTTPS Plugin Still Safe To Use? [closed]
- Set a User as Author of all ‘New Posts’ posted
- Post source link plugin – small modification
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- What is the function to get plugin base url in multisite?
- Code in theme functions.php faster than with a plugin?
- How can I make the “Preview Post” button save and preview in the same window?
- Override the core function locate_template
- Has anyone used require.js for handling plugin scripts?
- javascript onload calling a function of a plugin
- Trying to count the total number of paragraphs inside a blog article
- How to get post URL in the_content filter?
- May i Use ShortCode in Template?
- Pass info from functions.php to plugin
- add_query_arg not working
- How to load plugin after page is loaded – pagespeed issues
- Inserting HTML tag with ACF into shortcode
- How to Display a Plugin function (content) on frontpage using index.php
- Theme my Login plugin, how to update fields
- get current date + 90 days and checking every day
- add image crop function like in wp customizer
- Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]
- How to edit content before post update
- How to create an input field, and base the output on spreadsheet data? [closed]
- WordPress + JavaScipt + AJAX + MySQL: insert query for form
- Customize permalink wordpress category id
- Admin style for just one plugin in dashboard
- Advanced AJAX Page Loader ignores other JS code
- WordPress 3.8.3. custom theme – sliders won’t load js/css files
- How to set Noindex to all wordpress pages in a catergory?
- Load Javascript from Plugin in One Page Only?
- How to keep variable `$post` to using in another file
- Plugin Development – Functions or Hooks?
- How to generate an all in one WordPress New content, plugin and theme update report on a website? [closed]
- wp_dequeue_script for a Plugin
- wc_get_template new template does not showing up
- Overriding an Array in a Plugin’s Class/Function from functions.php
- Change Header (Logo) Based on Login
- How can i list random author?
- Can you echo PHP code from a variable?
- Defining the value of a variable before a function?
- How to get custom minimum price in Woocommerce
- Dynamic URL Rewrite for Custom
- how to validate input field in wordpress generated with wpform plugin
- Upload Javascript and json webpage to wordpress
- Error using wordpress functions inside a plugin class
- Get the link title attribute and send it google analytics as custom label via google tag manager using beehive pro for WordPress
- Calling PHP function with AJAX
- Share my WordPress plugin for updating how?
- The function called on the wp head hook becomes null
- Submitting form to PHP
- How can I add a custom Javascript snippet to display my feedback in footer?
- How to detect 404 url and make this link underline or change background color?
- working code, not working – Plugin Dev
- How to add defer to WordPress Plugin javascript? [duplicate]
- How to get Angular app working in WordPress plugin?
- how can export data in excel file custom plugin
- Custom Field used to allow a Free Story; no longer works
- Create a form and have custom menu display based on user answers?
- WP_CRON issue with UTC and local time
- How to wrap image tag into div for post only?
- Update User Meta Via Ajax
- How to print shortcode with js in visual composer?
- Unexpected plugin_dir_path Output
- how to repeat taxonomy in different places on wordpress
- how to create table during plugin installation in side a class
- Posting code inside the post instead of in the template file using shortcode
- Metabox Data not saving
- Can’t insert files in other inputs
- Can’t get custom user meta to show in header
- Including a PHP file via a function that is part of a plugin?
- Is it possible to run javascript on plugin deactivated?
- overwrite a plugin function in functions.php
- Pass strings to plugin function [closed]
- How do I output user_registered time in my correct timezone?
- Ajax in Plugins: returns the whole page
- WP Members additional fields on user profile [closed]
- Integrate Razorpay quick payments plugin with contact form7 plugin
- Notifications Bar on home page only
- Defer parsing of JavaScript [duplicate]
- How do I put a word-press blog into my static site without installing wordpress on server?
- How to Add Extra Text In WordPress Title Before Post Publish
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- Select posts from list and add them in a new list
- WordPress Convert queries to slashes using function.php