Meta Box
Support › General › OEmbed Empty Control
Hi,
How can I check empty control when I use OEmbed? If it empty, it return "Embed HTML not available".
Thanks! Kind regards.
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.
rwmb_meta()
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
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.
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 }