Using ACF field to embed media player scripts

Hi there.

I have a custom field (via ACF) that contains a Javascript media player embed code, like:

<div id="buzzsprout-player-1234567"></div>
<script src="https://www.buzzsprout.com/12345/12345-episode&player=small" type="text/javascript" charset="utf-8"></script>

I am trying to get this embed code to render on the frontend but I can’t seem to figure it out.

I’ve tried using a code block element and inserting the field like this:

But that doesn’t work.

The code block is signed. Code execution is turned on. Everything should be fine. I’ve tried changing the ACF field to text, text area, code, WYSIYG, etc. None of that helps.

If I hardcode the same identical embed code into the page template inside a code block it renders just fine.

How can I get this custom field to load the media player properly on the front end?

I suspect some sanitising is going on. I have a vague memory that ACF won’t pass code.
Could you use a URL field instead, then add a code block with:
<script src="{acf_field_name}" type="text/javascript" charset="utf-8"></script>
So all the html is in the script block and ACF just returns the url?

Bingo! That did it.

Changing the field type to URL and then passing that into a code block worked great:

Thank you!

@foliot, I’m attempting something similar and might be running into a similar sanitization issue.

I’ve got a JS embed code from Fusebox where I’ve replaced the podcast episode’s ID with the ACF placeholder, pulling the ID from my ACF text field assigned to the post.

ACF custom field placeholder for podcast track ID

However, nothing is displaying on the front end as seen here:

The code seems to be output just fine in the HTML of the page, but the player is hiding. Unfortunately, this site is under development, so I don’t have a publicly shareable link. Any ideas on what might be going on here?

I placed the script in the PHP/HTML portion of the code element and reformatted the script tags as @Matej with Bricks support suggested in my support ticket, and now I see the podcast player displaying and functioning properly on the frontend:

This Works!

Fusebox Podcast Player Working

I was, improperly, placing the embed code for the podcast player in the custom JS tab of the code element. The correct syntax for my particular ACF setup (pulling the podcast episode’s ID from a custom field) is below:

<script data-type="track" data-track="{acf_fusebox_podcast_player_track_id}" src="https://app.fusebox.fm/embed/player.js" type="text/javascript" charset="utf-8"></script>

I can confirm this is working for me. Thanks again, @Matej!

1 Like