Tuxy
Tuxy

Reputation: 91

Show popup time delay in Wordpress

I used a Wordpress theme where a popup is build in. The popup shows when click on this link:

<a href="#etheme-popup" class="etheme-popup">Nieuwsbrief</a>

So it activated with this id etheme-popup

Now i want trying the popup shows automatic after a delay of 2 seconds. So adding this code snippet, but doesn't work:

  <script>
  jQuery(document).ready(function($) {
  setTimeout(function() {
    $('#etheme-popup').show(); }, 2000);
  });
  </script>

Hope somebody can help me.

PS: Adding the code in theme's functions.php:

function popup_delay() {
  $newsletter_popup = '
  <script>
  jQuery(document).ready(function($) {
  setTimeout(function() {
    $(\'#etheme-popup\').show(); }, 2000);
  });
  </script>';
  echo "\n" . $newsletter_popup;
}
add_action('wp_footer', 'popup_delay', 20);

Upvotes: 1

Views: 768

Answers (1)

A. Iglesias
A. Iglesias

Reputation: 2675

If the anchor is doing what you want (the behaviour is already handled by the theme), you can trigger the click event of that anchor...

$(document).ready(function() {
    setTimeout(function() {
        $('a.etheme-popup').trigger('click');
    },2000);
});

Upvotes: 1

Related Questions