Support » Fixing WordPress » Inserting a Shortcode into conditional with Custom Field

  • Resolved cmdshiftdesign

    (@cmdshiftdesign)


    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%5D

    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%5D but …not as code, but as text — so it’s not being translated to the audio player.

    Eh?

Viewing 5 replies - 1 through 5 (of 5 total)
  • tresinvolved

    (@tresinvolved)

    How about if you do:

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

    Where is the code coming from? A template file?

    try wrapping it in wpautop

    tresinvolved

    (@tresinvolved)

    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] ') . '';
       }
        ?>

    cmdshiftdesign

    (@cmdshiftdesign)

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

    tresinvolved

    (@tresinvolved)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Inserting a Shortcode into conditional with Custom Field’ is closed to new replies.