0

I have this code that displays an mp3 link I have uploaded,

    <?php the_field('preview'); ?>

But I want to display it inside this shortcode where it says URL OF THE MP3 FILE;

    <?php echo do_shortcode("[sc_embed_player fileurl="URL OF THE MP3 FILE"]"); ?>

I'm having issues on doing this. Basically the short code is a play button and the the_field preview displays the mp3 link that the play button needs in order to play the mp3 link.

1

get_field returns a value, whereas the_field echos it. You need the value to be returned into your shortcode string so do_shortcode() can read and process it. Also you need to escape the double quotes or use single quotes on fileurl= ""

So, assuming preview is just the URL (and not a full HTML link) - I think the following should work:

<?= do_shortcode("[sc_embed_player fileurl='".get_field('preview')."']"); ?>

(If preview is a HTML link, just paste it in your original post, comment on this answer, and I'll update my answer).

Hope this helps.

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.