The oembed_iframe_title_attribute WordPress PHP filter allows you to modify the title attribute of the given oEmbed HTML iframe.
Usage
add_filter('oembed_iframe_title_attribute', 'your_custom_function', 10, 4); function your_custom_function($title, $result, $data, $url) { // Your custom code here return $title; }
Parameters
$title
(string) – The title attribute.$result
(string) – The oEmbed HTML result.$data
(object) – A data object result from an oEmbed provider.$url
(string) – The URL of the content to be embedded.
More information
See WordPress Developer Resources: oembed_iframe_title_attribute
Examples
Add a prefix to the title
This example adds a prefix to the title attribute of the oEmbed iframe.
add_filter('oembed_iframe_title_attribute', 'add_title_prefix', 10, 4); function add_title_prefix($title, $result, $data, $url) { $prefix = 'Video: '; $new_title = $prefix . $title; return $new_title; }
Make the title uppercase
This example changes the title attribute to uppercase.
add_filter('oembed_iframe_title_attribute', 'uppercase_title', 10, 4); function uppercase_title($title, $result, $data, $url) { return strtoupper($title); }
Append the website name to the title
This example appends the website name to the title attribute.
add_filter('oembed_iframe_title_attribute', 'append_site_name', 10, 4); function append_site_name($title, $result, $data, $url) { $site_name = get_bloginfo('name'); $new_title = $title . ' | ' . $site_name; return $new_title; }
Remove numbers from the title
This example removes numbers from the title attribute.
add_filter('oembed_iframe_title_attribute', 'remove_numbers', 10, 4); function remove_numbers($title, $result, $data, $url) { $new_title = preg_replace('/\d/', '', $title); return $new_title; }
Replace a specific word in the title
This example replaces a specific word in the title attribute.
add_filter('oembed_iframe_title_attribute', 'replace_word', 10, 4); function replace_word($title, $result, $data, $url) { $search = 'OldWord'; $replace = 'NewWord'; $new_title = str_replace($search, $replace, $title); return $new_title; }