You well need to add a filter to the_content
and alter the markup. This should replace the markup for <a>
tags having URLs ending in .mp3
, which you mentioned specifically in a comment.
function replace_audio_link_cb_105555($match) {
if (!empty($match[1]) && '.mp3' == substr($match[1],-4)) {
$your_long_block_of_markup = '<div id="jquery_jplayer_#uniqueid" class="jp-jplayer"></div>
<div id="jp_container_#uniqueid" class="jp-audio">... and so on ...</div>';
$your_javascript="<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#jquery_jplayer_#uniqueid").jPlayer({
ready: function () {
jQuery(this).jPlayer("setMedia", {
m4a: "#the_url_from_the_anchor_tag",
}) //.jPlayer("play");
},
swfPath: "js/jplayer",
supplied: "m4a, mp3, oga",
wmode:"window",
cssSelectorAncestor: "".$match[1].'"
});
});
</script>';
$match[0] = $your_long_block_of_markup.$your_javascript;
}
return $match[0];
}
function replace_audio_link_105555($content) {
$pattern = '|<a.*?href="https://wordpress.stackexchange.com/questions/105555/(.*)".*>?.*?(?:</a>)?|';
$content = preg_replace_callback($pattern,'replace_audio_link_cb_105555',$content);
return $content;
}
add_filter('the_content','replace_audio_link_105555');
If it were me, I’d work out a way to make that javascript a bit more flexible so that I could register and enqueue it, rather than print it independently for each audio file.