Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save meghansmith/4ab08fdac100a3963bb06aedeff9a7bd to your computer and use it in GitHub Desktop.

Select an option

Save meghansmith/4ab08fdac100a3963bb06aedeff9a7bd to your computer and use it in GitHub Desktop.
Append a Download link to the WordPress audio shortcode output

This adds a Download button to media player in Wordpress. If you want it all in one line, use the recommended styles below.

Changes from original: remove paragraph tags, add classes to button, remove inline styles, remove anchor tag. Make more semantic & editable. Include CSS for all-in-one-line display.

Recommended CSS for the bar/Download button on the same line: .wp-audio-shortcode { max-width: 79%; float: left; } a.downloadBtn { margin-top: 2px; margin-left: 10px;

/Optional button styling if not bootstrap site/ background-color: white; padding: 8px 10px; border-radius: 4px; border: 1px solid #333; color: #333; text-decoration: none; }

html:'<!--[if lt IE 9]><script>document.createElement(\'audio\');</script><![endif]-->
<audio class="wp-audio-shortcode" id="audio-1492-1" preload="none" style="width: 100%;" controls="controls"><source type="audio/mpeg" src="http://example.com/wp-content/uploads/2017/02/audio-track.mp3?_=1" /><a href="http://example.com/wp-content/uploads/2017/02/audio-track.mp3">http://example.com/wp-content/uploads/2017/02/audio-track.mp3</a></audio>'
atts:array (
'src' => '',
'loop' => '',
'autoplay' => '',
'preload' => 'none',
'class' => 'wp-audio-shortcode',
'style' => '',
'mp3' => 'http://example.com/wp-content/uploads/2017/02/audio-track.mp3',
'ogg' => '',
'wma' => '',
'm4a' => '',
'wav' => '',
)
audio:NULL
post_id:1492
library:'mediaelement'
<?php
add_filter( 'wp_audio_shortcode', 'ast_audio_shortcode_filter_test', 10, 5 );
function ast_audio_shortcode_filter_test( $html, $atts, $audio, $post_id, $library ) {
error_log( "html:".var_export( $html, true )."\natts:".var_export( $atts, true )."\naudio:".var_export( $audio, true )."\npost_id:".var_export( $post_id, true )."\nlibrary:".var_export( $library, true )."\n" );
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment