plugins - ACF for audio url in wordpress audio shortcode

admin2025-06-06  8

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

[audio src=""]

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)

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)

Share Improve this question asked Nov 20, 2018 at 7:33 JackBJackB 51 silver badge3 bronze badges 3
  • Have you tried with [acf field='sound_file_1'] ? – Sally CJ Commented Nov 20, 2018 at 7:43
  • @SallyCJ yes, it was the first Idea that I have tested – JackB Commented Nov 20, 2018 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 Commented Nov 20, 2018 at 8:23
Add a comment  | 

1 Answer 1

Reset to default 1

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]

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749164415a316907.html

最新回复(0)