oEmbed

Improve this page

Overview

The oEmbed field creates a simple text input for entering media URL. This field offers live preview the media content. It supports many media websites.

Screenshot

oembed

Settings

Besides the common settings, this field has the following specific settings:

Name Description
size Input size. Default 30. Optional.
not_available_string The text message displayed to users when no the embed is not available. Accepts HTML.

Sample code

array(
    'id'    => 'oembed',
    'name'  => 'oEmbed(s)',
    'type'  => 'oembed',

    // Input size
    'size'  => 30,
),

Data

This field saves the media URL in the post meta.

Template usage

To output the media in the frontend, use the rwmb_meta() helper function:

$media = rwmb_meta( $field_id );
echo $value;

This helper function will display the oembed content, e.g. if the value is a Youtube URL, it will display the full Youtube video player.

In case you want to get the URL of the field, use this code:

$url = rwmb_get_value( $field_id );
echo $url

Read more about rwmb_meta() and rwmb_get_value().

Hooks

The oembed field has one filter rwmb_not_available_string, which allows users to change the message for all oembed field when no embed is available.

Use the filter as follows:

add_filter( 'rwmb_not_available_string', function( $message ) {
    $message = 'Sorry, what you are looking here is not available.';
    return $message;
} );

Developers also can hide the message with CSS, since it’s wrapped into a div.rwmb-oembed-not-available. Simply put this code into your theme or in Customize > Additional CSS:

.rwmb-oembed-not-available {
    display: none;
}