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
- Can the new 4.8v text widget visual editor be removed?
- Where and how to put inline js in pages
- ajax live search for post title
- Show/hide Widgets in Dashboard Based on Current Advanced Custom Fields Option
- remove from text-widget
- Programmatically Add Font-Awesome Icons to Category Widget
- Dynamically Register Sidebars For Each Top Level Page
- Customising widget titles/headings in WP 5.8
- Widgets Section not displaying in theme customizer
- Run Product Filter Javascript On Page Template
- Displaying Widgets
- Enqueuing Script in functions.php vs on the page
- Increment price for Woocommerce Minicart [closed]
- javaScript in section of WP API
- jquery won’t load in footer
- Missing argument 2 for a custom function widgets_init
- How to properly add NPM packages and integrate them in WordPress?
- Slide in Panel WordPress Post
- Include chat (HTML, js, css) in all pages of WordPress
- Get Current User info using wp_localize_script, in functions.php
- How to get the post_name when in preview?
- Replace menu links with # and add name to its li
- Adding widget to dashboard with wp_dashboard_setup not working
- How to insert custom widget in custom sidebar in theme activation?
- Passing values from a widget to a function within a plugin
- Using Schema with `the_excerpt`
- Populate dropdown with Child Pages based on Parent Page chosen
- Best practices regarding the creation of custom widgets?
- How can I make a widget shortcode to control all the widgets?
- Including a specific Javascript Script in a template. Is my code correct?
- How to search using ajax for exact phrase or words in an input field?
- how to en-queue jQuery to load before the tag
- Replace a menu with widget or a custom template file programmatically
- How do I remove the date and category form my portfolio pages
- Dashboard widget custom positioning?
- Noscript not working as it should in wordpress site
- 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
- Javascript not loading after the document ready
- Create a Woocommerce product widget with category filter
- Add element to widgetpage
- “All posts” in the category widget
- How to load jQuery in TOP of wp_footer?
- Include Jquery libraries in wordpress theme?
- How to echo Widget Title in Custom Frontend-Template Box
- New checkbox in custom widget isn’t saving data
- 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 setup a popup registeration page in wordpress with function.php
- Shortcode of a function
- Add a custom function to widget code
- Time Delay a URL Redirect for Specific Page
- 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
- 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
- Help wiht adding fullcalendar.io to a WordPress page
- Add schema to Search result page’s body. Tried using is_search
- How to add widget in main menu
- Adding A New Widget to WordPress Disables the Existing Widgets
- Get child-pages slugs of current page into js-file
- Javascript and Stylesheet in child page
- Search and Replace Script Loader in Head Only Works in Footer
- custom post with loading script per single post
- wp_nav_walker that interacts with widgets to setup mega menu
- How to programmatically GET (to know) which Sidebar (or) which Menu is being used on Different Pages?
- Why are some custom javascript files working but some are not
- Register a widget area when a theme option has been saved?
- java script error Uncaught SyntaxError: Unexpected token ILLEGAL
- Give a function a unique ID
- How do I get my nav menu to show sub pages?
- Why wp_ajax hooks doesn’t work?
- comment_post function with js not running
- dynamically import array from another js file in WordPress
- Swap WordPress “Widget Area” based on Page Template