Using WordPress ‘oembed_min_max_width’ PHP filter

The oembed_min_max_width WordPress PHP filter modifies the allowed minimum and maximum widths for the oEmbed response.

Usage

add_filter('oembed_min_max_width', 'your_custom_function_name');
function your_custom_function_name($min_max_width) {
  // your custom code here
  return $min_max_width;
}

Parameters

  • $min_max_width (array): Contains the minimum and maximum widths for the oEmbed response.
    • min (int): Minimum width. Default 200.
    • max (int): Maximum width. Default 600.

More information

See WordPress Developer Resources: oembed_min_max_width

Examples

Change minimum and maximum widths

Modify the minimum and maximum allowed widths for the oEmbed response.

add_filter('oembed_min_max_width', 'change_oembed_min_max_width');
function change_oembed_min_max_width($min_max_width) {
  $min_max_width['min'] = 300;
  $min_max_width['max'] = 800;
  return $min_max_width;
}

Set fixed width for oEmbed response

Set a fixed width for the oEmbed response.

add_filter('oembed_min_max_width', 'fixed_oembed_width');
function fixed_oembed_width($min_max_width) {
  $min_max_width['min'] = 500;
  $min_max_width['max'] = 500;
  return $min_max_width;
}

Allow only maximum width for oEmbed response

Allow only maximum width for the oEmbed response, keeping the minimum width as default.

add_filter('oembed_min_max_width', 'set_max_oembed_width');
function set_max_oembed_width($min_max_width) {
  $min_max_width['max'] = 1000;
  return $min_max_width;
}

Allow only minimum width for oEmbed response

Allow only minimum width for the oEmbed response, keeping the maximum width as default.

add_filter('oembed_min_max_width', 'set_min_oembed_width');
function set_min_oembed_width($min_max_width) {
  $min_max_width['min'] = 150;
  return $min_max_width;
}

Disable minimum width constraint for oEmbed response

Remove the minimum width constraint for the oEmbed response.

add_filter('oembed_min_max_width', 'disable_min_oembed_width');
function disable_min_oembed_width($min_max_width) {
  $min_max_width['min'] = 0;
  return $min_max_width;
}