function my_scripts() {
// Register the script like this for a plugin:
wp_register_script( 'custom-script', plugins_url( '/js/custom-script.js', __FILE__ ) );
// or
// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/custom-script.js' );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'custom-script' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
Source :wordpress codex
Related Posts:
- Scripts not appending to element in AJAX call – why?
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- Creating multiple category drop down
- Creating a custom wordpress widget and stopping js from running twice(once in active widget once in widget selector)?
- Some code is added automatically to my site’s header – what is it?
- Automatic add space if user enters number(any digit)
- WordPress Javascript Widget jQuery Dependency Issue
- Can’t find function which is called in a wordpress theme
- Function to filter numbers from string
- Can the new 4.8v text widget visual editor be removed?
- How to influence the information displayed on widget inside wp-admin
- Where and how to put inline js in pages
- How to add css class to cloud tag anchors?
- Why won’t my scripts load?
- Loading CDN that requires jQuery in WordPress
- How to insert custom widget in custom sidebar in theme activation?
- How to hide unused profile fields?
- wp_register_script(… $in_footer = true) not working
- Right way to update widget on dynamic new input field
- Passing values from a widget to a function within a plugin
- Override widget in function WordPress
- Using Schema with `the_excerpt`
- Populate dropdown with Child Pages based on Parent Page chosen
- Best practices regarding the creation of custom widgets?
- WordPress Menuing Question :focus
- call of javascript function to external url always blocked by cors
- Remove after images
- How can I make a widget shortcode to control all the widgets?
- Including a specific Javascript Script in a template. Is my code correct?
- Warning: : DOMDocument::loadHTML(): Empty string supplied as input in functions.php when adding classes to post images
- How to search using ajax for exact phrase or words in an input field?
- how to en-queue jQuery to load before the tag
- Overwriting the menu break points of twentysixteen in child theme
- Replace a menu with widget or a custom template file programmatically
- How do I remove the date and category form my portfolio pages
- I can’t enqueue my scripts – They literally aren’t being added to my site
- PHP mixed with some JS code to update WordPress theme settings
- Custom taxonomy widget in admin area
- Dashboard widget custom positioning?
- How do you Permanently Delete Sidebars
- Add a unique class to HTML tag/element
- WordPress Shortcode function display outside of widget
- Get rid of the widget Item Class=”widget-item”
- Noscript not working as it should in wordpress site
- Javascript function not working when placed in Text Block
- Custom Sidebar only on single post
- Make wp_link_pages() suitable for Twitter Bootstrap markup
- Widget back end radio button issue
- I have problems with loading javascripts
- echo custom fields with AJAX
- Adding javascript to functions.php causes problems with my template
- Dequeue script to prevent javascript event conflict on wordpress child theme
- Can’t Write Custom Widget Code In One ECHO
- javascript and css links not working on sever
- Run a jquery script on on a certain template page
- Enable right click on WordPress site
- Why is it so hard to add a class to the tag in the sidebar widget?
- Javascript not loading after the document ready
- Theme JS is available but theme CSS isn’t
- Passing user enetered value in widget: number of words, for example
- Create a Woocommerce product widget with category filter
- Need help with customalert that it would read on a normal page, but not in WordPress
- Add element to widgetpage
- “All posts” in the category widget
- How to load jQuery in TOP of wp_footer?
- Register_Sidebar overwriting itself and doesn’t exist in global $wp_registered_sidebars;
- Include Jquery libraries in wordpress theme?
- widgets not working
- How to echo Widget Title in Custom Frontend-Template Box
- New checkbox in custom widget isn’t saving data
- Linking Javascript in functions.php file
- the_widget() inside functions.php
- Dequeue scripts in IE7 only using functions.php
- Why a SlideShow (made using JQuery FlexSlider) can’t work if I load it form functions.php but work if I load it from my footer.php file? [closed]
- How to conditionally add a widget via a hook in functions.php
- How Do I include/Import a Custom Widget from the Parent theme into My Child Theme?
- How to setup a popup registeration page in wordpress with function.php
- Shortcode of a function
- Custom attributes to javascript tags
- wp_enqueue_script() not working
- Add a custom function to widget code
- How to change text color depending on the number value (Using javascript)
- Time Delay a URL Redirect for Specific Page
- Include widget file in functions.php of child theme
- Add custom taxonomy using JS in post editor
- WordPress User Meta value variable into Google Gauge Chart
- wp_set_object_term via js btn frontend
- Adding HTML Code to Replace Text in PHP
- Display Script in Header When URL Variable Present
- Enable accessibility mode in widget as default
- Running javascript without hooking wp_head
- how to check if an element in an html file exists in another html file? [closed]
- Widget is displayed in two places
- Trying to change widgets h-tags
- Ajax in plugin fails – but only on one blog – no idea why
- How to add javascript code into Divi child theme?
- Changing the default view of “The Events Calendar” for mobile
- How do I make a custom “Read More Blogs” button for my blog page
- Extend WordPress Audio Widget to accept HLS (.m3u8) URLs
- Images with overlay