This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
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 );
If you’re having any trouble using this hook or need customization, feel free to Contact Us. We’re here to help!
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.