This WordPress shortcode plays an audio file for you and works great:

[audio src="http://XXX.mp3"]

In a specific post or page ,I want to give it the url of song using Advanced Custom filed (ACF) plugin:

[audio src="[acf field="sound_file_1"]"] 

but It does not work and tries to open [acf feild"... as the song url.
(Note that I have defined the url field using acf and tested it alone without audio shortcode and it works)

  • Have you tried with [acf field='sound_file_1'] ? – Sally CJ Nov 20 '18 at 7:43
  • @SallyCJ yes, it was the first Idea that I have tested – JackB Nov 20 '18 at 8:02
  • It's probably because WordPress doesn't support nested shortcodes, and the default [audio] shortcode also doesn't parse shortcode in the audio source (i.e. the src parameter). However, you can overcome that, by creating a custom shortcode - e.g. [audio_acf] – Sally CJ Nov 20 '18 at 8:23

I havent tested yet but I think can work, what I would do is create a function to create a new shortcode from those to doing this.

function new_shortcode() {
$urlmusic = get_field('sound_file_1');

echo do_shortcode("[audio src='$urlmusic']");

add_shortcode( 'audioACF', 'new_shortcode' );

Use [audioACF]

  • thank you, actually your answer needs a correction to work, I have corrected and worked: `echo do_shortcode(("[audio src='$urlmusic']"); – JackB Nov 21 '18 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.