I have Wordpress site for my podcast. I have set up a preview button (using span
) with a short audio file to accompany each post in a category. The audio files are called with a custom post field, "audio_preview".
I would like to set the button to play audio files on-click. For now, clicking a button will exit the current page and redirects to the file itself. Here's an example page and the button's code.
<span class="entry-preview-button"><a class="entry-preview-button" href="<?php echo get_post_meta($post->ID, 'audio_preview', true); ?>"><i class="fa fa-volume-down"></i> Preview</a></span>
It appears I need to use JavaScript's onclick function to do this. However, my problem is this bit of PHP.
<?php echo get_post_meta($post->ID, 'audio_preview', true); ?>
Things go wrong when I try to enclose the button in a script. I've tried modifying the code to the extent of my abilities, including using input
tags instead of span
tags. The best I can do is have one file play for every button on the page instead of the respective files.
What am I missing?