1

Can anyone help me to find which action and how that is used to display an alert message while load the web page in WordPress.

Is it possible to use wp_head action? How would I do that?

Marcin Orlowski
  • 67,279
  • 10
  • 112
  • 132
ani
  • 177
  • 1
  • 2
  • 7

1 Answers1

1

Yes you can use wp_head hook to output custom style and js in WordPress <head> tag.

Try this,

function your_function()
{
    ?>
    <script type="text/javascript">
        function codeAddress() {
            alert('ok');
        }
        window.onload = codeAddress;
    </script>

    <?php
}

add_action('wp_head', 'your_function');

This code is tested and is fully functional.

Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.

Reference: run function when page is loaded

Community
  • 1
  • 1
Raunak Gupta
  • 8,726
  • 2
  • 41
  • 78