Product:
WonderPlugin Audio Player
Question:
I wonder is there a way to play an audio snippet 30 seconds after someone lands on any page of my website, but I would only want it to play once...not each time they go to a new page. Is that possible and would it be simple to do?
Answer:
In your WordPress backend, goto menu Appearance -> Editor, find the file Theme Header "header.php", click and edit it, then add the following JavaScript to the head section of the code, just before the head closing tag :
<script> (function($){ $(document).ready(function() { var wonderpluginaudioplayed = false; var cookies = document.cookie ? document.cookie.split(';') : []; for (var i in cookies) { var parts = cookies[i].trim().split('='); if (parts.length && parts[0] == 'wonderpluginaudioplayed') { wonderpluginaudioplayed = true; break; } } if (wonderpluginaudioObjects && !wonderpluginaudioplayed) { setTimeout(function() { wonderpluginaudioObjects.objects[0].audioRun(0, true); }, 30000); document.cookie = 'wonderpluginaudioplayed=1;path=/'; } }); })(jQuery); </script>
The code will automatically activate the player and play the audio 30 seconds after the visitor lands on the first page of your website. Of course, you need to add the audio player to all of the related webpages.
And the autoplay won't work on mobile and tablets. It's a limit from iOS and Android.