Title: Audio Player Shortcode
Last modified: May 7, 2018

---

# Audio Player Shortcode

 *  [WriterDan](https://wordpress.org/support/users/writerdan/)
 * (@writerdan)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/audio-player-shortcode/)
 * There are currently only 3 options for the placement of the audio player within
   a post:
 * Before Post
    After Post Do Not Show
 * I’d like to suggest that you offer a “Custom Position” option that would require
   that the user include a shortcode (like [polly_player] for example) that would
   allow us to place the audio player wherever we want within the content, or even
   multiple times within the content, if we wish.
 * Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Contributor [tstachlewski](https://wordpress.org/support/users/tstachlewski/)
 * (@tstachlewski)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/audio-player-shortcode/#post-10323874)
 * Hi [@writerdan](https://wordpress.org/support/users/writerdan/)!
    Would this 
   player provide audio for the whole post or some ‘specific’ content which would
   be provided in shortcode? If the first option, any reasons why would this functionality
   be useful? (I’m just trying to understand how important this is 🙂 ).
 *  Thread Starter [WriterDan](https://wordpress.org/support/users/writerdan/)
 * (@writerdan)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/audio-player-shortcode/#post-10323966)
 * Essentially, right now my only options are to place the player:
 * 1) At the very beginning of the post
    2) At the very end of the post 3) Nowhere
   in the post
 * I’ve actually written my own custom shortcode to accomplish this on our site 
   for the time being. I did this so that we could place the player in the correct
   location for this post:
 * [https://www.esupplements.com/best-l-glutamine-supplements/](https://www.esupplements.com/best-l-glutamine-supplements/)
 * We have that left-floating meta-information section that comes first in the article,
   and we wanted the player to show up at the “top” of the article content but after
   that meta-information section.
 * Here’s my custom code:
 *     ```
       function amazon_polly_player_shortcode($atts, $content = NULL) {
       	global $post;
   
       	$tagged_content = '';
       	if(intval(get_post_meta($post->ID, 'amazon_polly_enable', TRUE))===1) {
       		$player_source = get_post_meta($post->ID, 'amazon_polly_audio_link_location', TRUE);
       		$tagged_content = PHP_EOL.'-AMAZONPOLLY-ONLYWORDS-START-'.PHP_EOL.'
       <table id="amazon-polly-audio-table">
       	<tbody>
       		<tr>
       			<td id="amazon-polly-audio-tab">
       				<div id="amazon-polly-label-tab">Listen to this article</div>
       				<div id="amazon-polly-play-tab">
       					<audio id="amazon-polly-audio-play" preload="none" controls="">
       						<source type="audio/mpeg" src="'.$player_source.'">
       					</audio>
       				</div>
       				<div id="amazon-polly-by-tab">
       					<a href="https://aws.amazon.com/polly/" target="_blank" rel="noopener noreferrer">
       						<img src=" https://d12ee1u74lotna.cloudfront.net/images/Voiced_by_Amazon_Polly_EN.png" width="100">
       					</a>
       				</div>
       			</td>
       		</tr>
       	</tbody>
       </table>'.PHP_EOL.'-AMAZONPOLLY-ONLYWORDS-END-'.PHP_EOL;
       	} else {
       		$tagged_content = PHP_EOL.'<!-- Amazon Polly not enabled on this post -->'.PHP_EOL;
       	}
       	return $tagged_content;
       }
       add_shortcode('polly_player', 'amazon_polly_player_shortcode');
       ```
   
 * Then I just put the [polly_player] shortcode in my content where I wanted the
   player to render. Seems to be working great for us, and it provided the ability
   to customize the post to how we wanted it to be.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Audio Player Shortcode’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/amazon-polly_303a47.svg)
 * [AWS for WordPress](https://wordpress.org/plugins/amazon-polly/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amazon-polly/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amazon-polly/)
 * [Active Topics](https://wordpress.org/support/plugin/amazon-polly/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amazon-polly/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amazon-polly/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [WriterDan](https://wordpress.org/support/users/writerdan/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/audio-player-shortcode/#post-10323966)
 * Status: not resolved