wp_register_script() is for telling WordPress about script files, and is a PHP function. It has no control over how the script executes, only where the <script></script> tag is output and what the URL is.
If you don’t want the script to execute until the page is loaded you need to put that JavaScript you posted in the relevant script file.
Related Posts:
- How to call a PHP function from Javascript in WordPress
- WordPress Infinite Scroll without using any plugin
- How to preserve PHP modifications while upgrading WordPress?
- Calling a method from functions.php on a click of a button
- How to use WordPress (PHP) functions in AngularJS partials files?
- Understanding WordPress child theme custom JS loading
- Click loads template via ajax
- javaScript in section of WP API
- How to speed up admin-ajax.php in wordpress
- Adding tawk.to code just before body tag on functions.php file
- How do I fetch all comments per post via WP REST API?
- Deregistering a script in WordPress seems impossible
- Slide in Panel WordPress Post
- How do I display a user’s previous orders as a select box option on a product?
- Trigger popup in a php if/else statement
- Use menu link or onClick to set a variable
- Populate dropdown with Child Pages based on Parent Page chosen
- remove wp floating submenu in wp dashboard
- How to complete two other input fields, completed the first
- JS file work only in index page
- dynamic dependent select dropdown
- Ajax load more button for comments wordpress
- Noscript not working as it should in wordpress site
- Why i can’t get custom fields value or post ID via Ajax?
- How to reference PHP in Javascript
- Time Delay a URL Redirect for Specific Page
- WordPress User Meta value variable into Google Gauge Chart
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Adding HTML Code to Replace Text in PHP
- Gutenberg block don’t save rich text content
- Trying to add some custom text into WordPress Post title via function.php
- Update $wpdb query with AJAX
- Using Javascript On Page – Header and Footer Now Missing
- Adding extra data to shortcode attributes and pass it to JS with wp_localize_script
- How do I make comment-reply-button with that takes to comment reply form on click
- custom post type column countdown
- How to call a function from functions.php with ajax?
- Custom Post type Ajax search results
- WordPress load javascript file if something… (after the page is loaded)
- Automatically refresh page if widget is added to page?
- wordpress all post filter by year
- Find the method which AJAX GET calls
- Display text of price (minus 20%) on every product page in a sentence.
- Help with my first Metabox helper class
- wp wp_register_script function results type parameter missing
- Trouble figuring out how to get my button to submit comment
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- hiddenQuestions.find is not a function
- Calling a function via a shortcode in javascript
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- Hide or Show Read More Button by Content Area
- How to draw media details for Isotope gallery using Photoswipe
- Remove wp-mediaelement.css from wp_head
- Using a function written in my functions.php file within the header.php file
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- WordPress Redirect: Default Password Reset URL [duplicate]
- AJAX request status 200 but no actual “response”
- How to prevent WP_Query function from returning all posts when empty?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- foreach loop still echoes array
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- wp-comments-post.php file returns a blank page
- Add .htm extention to a custom taxonomy
- php syntax : [ && ] between commands [closed]
- Which PHP page is the Default Posts Page
- Need to put a script above tag in header.php – WP 5.7.1
- How to use theme function in post/page?
- Why does the post_type_link hook everything twice?
- Warning: in_array() null given in PHP function
- wp_nav_menu not working correctly in my underscores theme
- use loop to return blog details
- How can I count ACF sub_field with a certain value
- Fetching Initials of the Commentator in the WordPress Website
- Adding function to child theme’s function.php
- WP Container Displaying Only on First Page of Archive
- Hook on file upload
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- How to move a post from one category to another
- How to override theme’s public static function inside of a trait?
- WP_Query To Display Product Of Brand On Taxonomy Page
- How can I export data without using any import/export plugin
- Search for images that width and height is more than 500
- wordpress ajax return 0
- I need help implement a Javascript code into the PHP file
- Admin bar nodes
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- How can I correctly POST to a WordPress page?
- Search box background on a different page template
- WP Ecommerce: Display the “Order Notes” as column in the Sales Log [closed]
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Load php function with AJAX on modal window
- A next page function with shortcode?
- What is the wrong with this function to enqueue the scripts and styles to the theme? [closed]
- Facing Problem While Running WordPress Hook For Archive, Categories, Author, Date Pages Only
- Custom Admin Menu Report for Specific User ID
- How to make this shortcode not refresh the whole page when i use it on frontend
- How to pass php array to external js file in WordPress