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
- Simple ajax request with Vanilla JS keeps given 400 Bad Request
- greatest() function returns undefined property
- Limit the number of plugins that can be installed in a WordPress installation
- Debugging Technique Question re: functions.php
- Add get_option to jquery
- Where to place custom functions?
- Localiztion in javascript
- Override plugin with functions.php
- WP-Cufon adding extra space in my paragraphs in Firefox and Chrome
- Scope for PHP Variables Assigned in functions.php or a plugin
- Override the filter from plugin in child theme
- The Point of Using apply_filters()
- How to get post URL in the_content filter?
- Add a plugin before main container
- WP Job Manager Category Drop-down; Change Placeholder Text Via Filter
- How to get subscription key or id using Woocommerce Subscriptions [closed]
- How to get variables from fucntion.php to my plugin files
- W3 Total Cache: Load CSS asynchronously for better PageSpeed score? [closed]
- Get all categories of custom post even not assigned
- How to include code into functions.php file via a plugin
- Function to prevent users from trashing comments
- Avoiding Duplicate function names in Post Loop (WP_Footer script)
- Custom Taxonomy Tag Search
- May i Use ShortCode in Template?
- Missing argument 3 for wp_register_sidebar_widget()
- Pass a php string to a javascript variable
- Redeclare theme’s function in a plugin
- How to add class in plugin only for network site?
- Pass info from functions.php to plugin
- How does WordPress process plugin installations?
- Problem in loading javascript in footer
- I have functions in my wordpress plugin. How do I get them to work for me?
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- JQuery not working in my plugin [closed]
- prettyPhoto media loading very slowly in Chrome
- How to create TEMPORARY Download links in a wordpress POST?
- Conditionally add apt. Open Graph meta data to different pages on WordPress site
- PHP Fatal error: Call to undefined function plugin_basename
- plugin development: problem with functions
- add_query_arg not working
- How to load plugin after page is loaded – pagespeed issues
- add mediaelement.js plugins into WordPress video player control bar
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- Is there a way I can find wordpress posts that don’t contain a word?
- Prevent shortcode from being wrapped in tags
- React JSX in WordPress Plugin Development
- AJAX button run function
- Internationalization autocomplete JS variable
- Dropdown menu on custom page with product to choose number of products per page
- Change wordpress current_time function to different timezone
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- Inserting HTML tag with ACF into shortcode
- Using custom JS plugins with WordPress?
- Executing my function once on a specific time
- Override Javascript in a Plugin?
- How to append to title via functions.php for auto-posting plugin [duplicate]
- How to stop or remove an action being called inside a function of an extended class
- Missing Argument
- load_plugin_textdomain error
- How to override a plugin function wrapped in a class?
- Bootstrap Drop Down menu is not working
- How to Display a Plugin function (content) on frontpage using index.php
- How to disable specific plugin in mobile version?
- Is there an earlier hook than login_head or login_enqueue_scripts?
- wordpress plugin is not activating from widget
- Best approach to fetch data from wp options to js file or php file
- Theme my Login plugin, how to update fields
- Edit Yoast SEO breadcrumbs output [closed]
- Adding Shortcode to Text Widget
- Date calculations from 2 custom fields
- Snippets: is it better to add them in functions.php or make site-specific plugins?
- Can someone please tell me what is wrong with my plugin?
- Does WordPress validate inputs to all functions? (such as get_user_meta and insert_user_meta)
- Updating the Drag-To-Share eXtended share URLs?
- Custom random quote widget breaks when used in multiple sidebars
- Scripts at the end of the page
- wordpress site | All-in-one-cufon IE Issue
- Enqueue WordPress plugin scripts below all other JS
- Using a function to change favorites listing
- How to add Internationalization in WordPress using Javascript/React?
- Can I use custom CSS and js plugin to put JavaScript in to validate my forms
- Display post lists in 2nd paragraph
- How to debug error message: Cannot modify header information
- Change upload folder for a CPT
- Using a post-signup hook to get user details
- How to enable specific plugin only based around shop manager role?
- How to change constants in WordPress wp-config.php programmatically?
- Restrict media upload size by format
- How to get the element ID from new menu list that added with add_filter()?