OEmbed Empty Control

Support General OEmbed Empty Control

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #8849
    dijitalgezgindijitalgezgin
    Participant

    Hi,

    How can I check empty control when I use OEmbed? If it empty, it return "Embed HTML not available".

    Thanks!
    Kind regards.

    #8852
    Anh TranAnh Tran
    Keymaster

    You can use the rwmb_meta() function, it will auto checks whether the media player is available. If not, it shows the "Embeded HTML is not available" message.

    If you want to check that your self, you can do similarly like here:

    https://github.com/wpmetabox/meta-box/blob/master/inc/fields/oembed.php#L41

    #8895
    dijitalgezgindijitalgezgin
    Participant

    Hi Anh,
    This is not good for me. Because If there isn't any embed, I don't want print HTML codes. How can I can check empty control?
    Kind regards.

    #8906
    Anh TranAnh Tran
    Keymaster

    In the link I pasted above, there's full code to detect if the URL is a valid oembed, you can try it, like this:

    $url = get_post_meta( get_the_ID(), 'oembed', true );
    $args = ['width' => 640];
    $embed = wp_oembed_get( $url, $args );
    if ( ! $embed ) {
        $embed = $GLOBALS['wp_embed']->shortcode( $args, $url );
    }
    if ( $embed ) {
        echo $embed;
    } else {
        // Do something when there's no controls if you want
    }
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.