How to trigger js event after page load in wordpress?

by elisha_langworth , in category: PHP CMS , a month ago

How to trigger js event after page load in wordpress?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , a month ago

@elisha_langworth 

To trigger a JavaScript event after the page has loaded in WordPress, you can add the following code to your theme's functions.php file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function my_custom_script() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            // Your JavaScript event code here
        });
    </script>
    <?php
}
add_action('wp_footer', 'my_custom_script');


Replace "// Your JavaScript event code here" with the actual JavaScript code you want to trigger after the page has loaded.


This code will add the JavaScript code inside a script tag in the footer of your WordPress site, ensuring that it is triggered after the page has loaded.