The embed_maybe_make_link WordPress PHP filter allows you to modify the returned, maybe-linked embed URL.
Usage
add_filter('embed_maybe_make_link', 'your_custom_function', 10, 2); function your_custom_function($output, $url) { // your custom code here return $output; }
Parameters
$output
(string) – The linked or original URL.$url
(string) – The original URL.
More information
See WordPress Developer Resources: embed_maybe_make_link
Examples
Add a CSS class to the embedded link
Add a custom CSS class to the embedded link for styling purposes.
add_filter('embed_maybe_make_link', 'add_css_class_to_embed', 10, 2); function add_css_class_to_embed($output, $url) { $output = str_replace('<a ', '<a class="custom-embed-class" ', $output); return $output; }
Add a data attribute to the embedded link
Add a custom data attribute to the embedded link for JavaScript usage.
add_filter('embed_maybe_make_link', 'add_data_attribute_to_embed', 10, 2); function add_data_attribute_to_embed($output, $url) { $output = str_replace('<a ', '<a data-custom-attribute="value" ', $output); return $output; }
Add a target attribute to open the embedded link in a new tab
Make the embedded link open in a new browser tab.
add_filter('embed_maybe_make_link', 'embed_link_new_tab', 10, 2); function embed_link_new_tab($output, $url) { $output = str_replace('<a ', '<a target="_blank" ', $output); return $output; }
Remove the link from the embedded URL
Remove the link from the embedded URL, displaying the URL as plain text.
add_filter('embed_maybe_make_link', 'remove_link_from_embed', 10, 2); function remove_link_from_embed($output, $url) { return strip_tags($output); }
Replace the embedded link with a custom link
Replace the embedded link with a custom link of your choice.
add_filter('embed_maybe_make_link', 'replace_embed_link', 10, 2); function replace_embed_link($output, $url) { $custom_link = 'https://www.example.com'; return str_replace($url, $custom_link, $output); }