I received the following question from a user today:
How can I use the audio player from my WordPress theme’s template file?
This is a quick tutorial for users who want to embed an audio file in their WordPress theme’s template file.
Embed Audio File in a Template File
Step 1. Install the Audio Player Plugin
Grab the audio player plugin from here.
Step 2. Use the PHP Code in Your Template File
Edit your template file and use the following PHP code (where you want to insert the audio player).
<?php $args = array('fileurl' => 'www.example.com/my-music/mysong.mp3'); echo sc_embed_player_handler($args); ?>
You will need to use the correct URL of the audio file that you want to embed.
You can also pass additional player parameters like the following example:
<?php $args = array('fileurl' => 'www.example.com/my-music/mysong.mp3', 'autoplay' => 'true', 'loops' => 'true'); echo sc_embed_player_handler($args); ?>
The above code should embed a playable audio file that looks like the following:
PHP Code for Template 1
Use the following code if you want to use audio player template 1:
<?php $args = array('fileurl' => 'www.example.com/my-music/mysong.mp3'); echo sc_embed_player_templater1_handler($args); ?>
Alternative Code
You could also use the following PHP code instead of the one shown above:
<?php echo do_shortcode('[sc_embed_player fileurl="www.example.com/my-music/mysong.mp3"]'); ?>
Any shortcodes that you see here can be used in your template file using the above technique.
Leave a Reply