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

How to use make_clickable_rel filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
March 19, 2023
5 minutes read

WordPress hooks are like secret ingredients that add flavor to your website’s functionality. One such hook is the make_clickable_rel filter. It’s all about filtering the rel value added to URLs converted into links. To use this filter, you’ll first need to register it using add_filter. You can add this to your theme’s functions.php or, as we recommend at WePlugins, create a custom WordPress Plugin to avoid any mishaps when updating your theme in the future.

In the following sections, you’ll find live examples demonstrating how to use this hook effectively. Let’s dive in!

Example 1: Basic Usage

Here’s a straightforward example of how to use the make_clickable_rel filter. This example shows how to modify the rel value according to your website’s requirements.

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

Example 2: Conditional Modification

Sometimes, you might want to conditionally modify the rel value based on the URL. Here’s how you can achieve that.

    function weplugins_conditional_rel_modifier($rel, $url) { 
        if (strpos($url, 'example.com') !== false) {
            $rel = 'nofollow';
        }
        return $rel; 
    }
    add_filter( "make_clickable_rel", "weplugins_conditional_rel_modifier", 10, 2 );
    

Example 3: Removing the Filter

If you ever need to remove the filter, you can do so using remove_filter. Just make sure you provide the same callback function name, priority, and number of arguments.

    remove_filter( "make_clickable_rel", "weplugins_modify_make_clickable_rel_defaults", 10, 2 );
    

Access Premium WordPress Plugins

If you’re having any trouble using this hook or need customization, feel free to Contact Us. We’re here to help!

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.