• 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

    (@tstachlewski)

    Hi @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

    (@writerdan)

    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/

    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.