0

Currently using CF Post Formats ( http://alexking.org/blog/2011/10/25/wordpress-post-formats-admin-ui ) and using the following code to automatically embed a URL that has been input into the 'Audio' or 'Video' custom field:

<?php echo wp_oembed_get( get_post_meta($post->ID, '_format_audio_embed', true) ); ?>

However, if oembed does not support the service (Eg. Spotify) and the user inputs the full embed code, it does not echo out anything.

How could I get around this so that if the user inserts code starting with something like:

<iframe...

then it won't use Oembed and instead it will display normally?

0

<?php if (strstr($audio, '<iframe')) { echo $audio; } else { echo wp_oembed_get( get_post_meta($post->ID, '_format_audio_embed', true) ); } ?>

Of course, this would require that you get the custom field with the audio embed code or url into $audio :)

Edit - try:

<?php $audio = get_post_meta($post->ID, '_format_audio_embed', true); if (strstr($audio, '<iframe')) { echo $audio; } else { echo wp_oembed_get( $audio ); } ?>

  • Great thanks so much! How would I get the url/audio embed code into $audio ? :-) – user2014024 Feb 28 '13 at 17:05
  • Try the edit. Let me know if that works for you. (I was a little tired when I answered the first time :) – jfacemyer Mar 1 '13 at 2:09
  • Works great - thank you for coming back and showing me the other part too! :) – user2014024 Mar 1 '13 at 12:18
  • No problemo! I realized that the answer was simple enough, and I should have given it completely the first time! – jfacemyer Mar 4 '13 at 3:38

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.