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!
WordPress

Avatar of undefined
Last Comment
Marcellino Santoso

8/22/2022 - Mon
Marcellino Santoso

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.
ASKER
1Cougar

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
Marcellino Santoso

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23