• Is it possible to add a title parameter to the default WP [audio] shortcode?

    I’ve created a site with hundreds of original audio tracks for music lessons. We have been using the mp3-jPlayer plugin, but that plugin has been abandoned so now I need to do something different and revise all of the existing shortcodes.

    The default WP audio player would be okay, except that I need to display the title of the audio track. Many of the mp3 files did not include a title in the metadata, and pulling a title from the media attachment would be complicated because the existing shortcodes use the URL of the audio file, not the attachment ID.

    The mp3-jPlayer plugin allowed us to set the track title manually in the shortcode, like this:

    [audio mp3="https://www.jamalong.org/wp-content/uploads/2018/11/backing-track-pallet-on-your-floor-A.mp3" title="Pallet on Your Floor - A" loop="y"][/audio]

    Is there a way to hack the default WP audio shortcode to display the existing titles?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You can override the entire shortcode handler, but then your callback is responsible for doing everything. There’s no way to add additional shortcode attributes that the WP handler code would recognize.

    However, there is the ‘wp_audio_shortcode’ filter where your callback can alter the eventual HTML output, so titles can be added that way. Your callback is passed the $atts array as the second parameter. Thus you could go ahead and add a title shortcode attribute and pick it up in your callback. WP wouldn’t know what to do with it, but as long as your callback does, it’s all good.

    Untested concept though. There’s a slight chance WP will drop attributes it doesn’t recognize and this concept will fail to work as desired.

Viewing 1 replies (of 1 total)
  • The topic ‘Add title parameter to [audio] shortcode?’ is closed to new replies.