Incorporate jquery into WordPress -
i trying incorporate simple audio player wordpress uses jquery control player , player control background image. there several instances of player on single page.
i have no problem writing code html page, doesn't work inside wordpress page. i've been googling couple hours, haven't found specific, understandable answer need, apologize if has been covered elsewhere.
i don't want write plugin, want able create little control on html5 audio player.
the script code:
$(document).ready(function(){ var allaudioels = $('audio'); function pauseallaudio(){ $('.gac_play').attr('src', 'play16.png'); allaudioels.each(function() { var = $(this).get(0); a.pause(); }); } $(".gac_play").click(function(){ var song = $(this).next('audio').get(0); if(song.paused){ pauseallaudio(); $(this).attr('src', 'pause16.png'); song.play(); }else{ pauseallaudio(); $(this).attr('src', 'play16.png'); } });
the html:
<img class="gac_play" src="play16.png" /> <audio> <source src="audio/fm-sample1.mp3" /> <source src="audio/fm-sample1.ogg" /> </audio>
works on html page, not in wordpress. assistance appreciated.
make sure you're enqueueing jquery file , use ready function such:
jquery(document).ready(function($){ // code goes here });
or can use $=jquery.noconflict();
in beginning of script tag. can check other errors in js console (ctrl+shift+j on chrome).
Comments
Post a Comment