Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use embed_maybe_make_link filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
February 26, 2023
5 minutes read

embed_maybe_make_link filter

Filters the returned, maybe-linked embed URL.

To use embed_maybe_make_link filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.

We at WePlugins always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.

In the below live example, we have defined a function modify_embed_maybe_make_link_defaults which takes 2 parameters and we registered using add_filter. The first parameter embed_maybe_make_link is name of the hook, The second parameter modify_embed_maybe_make_link_defaults is name of the function which need to be called, third parameter is the priority of calling the hook if same hook is used multiple times and the last parameter is the number of arguments (if any) to be passed in the registered function.

Sometimes, you have to remove a registered hook so you can use remove_filter to remove embed_maybe_make_link filter.

Parameters

Below are the 2 parameters required to use this hook.

  • $output : (string) The linked or original URL.
  • $url : (string) The original URL.

Live Examples

Example 1: Basic Usage

This example demonstrates how to modify the $output variable using the hook.

    function weplugins_modify_embed_maybe_make_link_defaults($output, $url) { 
        // Update the $output variable according to your website requirements and return this variable.
        return $output; 
    }
    // add the filter
    add_filter( "embed_maybe_make_link", "weplugins_modify_embed_maybe_make_link_defaults", 10, 2 );
    

Example 2: Conditional Modification

This example shows how to modify the $output variable conditionally based on certain criteria.

    function weplugins_conditionally_modify_embed($output, $url) {
        if (strpos($url, 'youtube.com') !== false) {
            $output = '<a href="' . $url . '">Watch on YouTube</a>';
        }
        return $output;
    }
    // add the filter
    add_filter( "embed_maybe_make_link", "weplugins_conditionally_modify_embed", 10, 2 );
    

Example 3: Removing the Hook

To remove a hook callback, use the example below. Make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

    // remove the filter
    remove_filter( "embed_maybe_make_link", "weplugins_modify_embed_maybe_make_link_defaults", 10, 2 );
    

Access Premium WordPress Plugins

Contact Us

If you need customization or are having trouble using this hook, please contact us. We’d be happy to assist you.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.