$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - ACF for audio url in wordpress audio shortcode|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - ACF for audio url in wordpress audio shortcode

matteradmin8PV0评论

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]

Post a comment

comment list (0)

  1. No comments so far