Link to home
Start Free TrialLog in
Avatar of 1Cougar
1Cougar

asked on

Add shortcode to play sound

Hello,

I am rather new to Wordpress backend and coding and would like to create a short code that can be put around a word in my post and when the user clicks the word a sound will be played.  I don't want to see a player...just have the sound played.  I would like to pass the content contained within the shortcode to the function.  So, it would look like this:

[playsound]content[/playsound]

I am not sure how to do this...many thanks for your pointers!
Avatar of Marcellino Santoso
Marcellino Santoso
Flag of Netherlands image

First, you need to create and define what the shortcode(s) does (do). If you don't know how to do so, this is a pretty good tutorial : http://wp.smashingmagazine.com/2012/05/01/wordpress-shortcodes-complete-guide/

Second, you need to have the player (obviously). You need to pass the parameter defined in your custom shortcode to the player.

As to not showing the player, you can simply add something like style="display:none;" to your player div. Since it's hidden, the play/stop control will not user-clickable, so in my opinion the player should be able to auto start and auto stop.

Maybe for future-proofing: HTML5 audio player: http://www.w3schools.com/html/html5_audio.asp -- and fallback scenarios: flash player, and non-flash, non-HTML5 audio player.
Avatar of 1Cougar
1Cougar

ASKER

Hello and thanks for your comments.  So, if I understand correctly:

I would add a player to the page template that is hidden.

I create a shortcode that passes content to the function that will then pass the parameter to the player (this part I am not sure how to write...)--do you have an example of that?

Finally, regarding the HTML5 player...do you mean I have multiple players?  Any idea of where to look for this and which ones to pick??

Thanks again,
ASKER CERTIFIED SOLUTION
Avatar of Marcellino Santoso
Marcellino Santoso
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial