WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Inserting a Shortcode into conditional with Custom Field (6 posts)

  1. cmdshiftdesign
    Member
    Posted 2 years ago #

    OK, so i have a custom field that is specifying the URL of an MP3 file for a podcast, and the end goal is for that URL to be inserted into the shortcode for the audioplayer...

    which looks like this [audio:http://domain.com/audio.mp3]

    SO I need something in the theme that says ...

    if there us something in the mp3_link field
    [audio: *stick it right here*]

    <?php $values = get_field('mp3_link');
    	   if($values)
       {
        echo '' . do_shortcode(' [audio:$values] ') . '';
       }
        ?>

    I know i am missing something... this is the code i have and it returns [audio:http://domain.com/audio.mp3] but ...not as code, but as text — so it's not being translated to the audio player.

    Eh?

  2. tresinvolved
    Member
    Posted 2 years ago #

    How about if you do:

    echo '' . do_shortcode(' [audio:' . $values . '] ') . '';

    Where is the code coming from? A template file?

  3. Andrew Norcross
    Member
    Posted 2 years ago #

    try wrapping it in wpautop

  4. tresinvolved
    Member
    Posted 2 years ago #

    Actually, from looking at the Audio Player FAQ, it looks like you want this instead:

    <?php $values = get_field('mp3_link');
    	   if($values)
       {
        echo '' . insert_audio_player(' [audio:$values] ') . '';
       }
        ?>
  5. cmdshiftdesign
    Member
    Posted 2 years ago #

    Kyle (tresinvolved) fucking wins! Thank you! YES!

  6. tresinvolved
    Member
    Posted 2 years ago #

    You may also want to do a

    if ( function_exists( 'insert_audio_player') )

    check somewhere there, just in case you remove the audio player plugin at some point.

Topic Closed

This topic has been closed to new replies.

About this Topic