How to change a WordPress plugin function using action hooks

This is just one of the many possible scenarios on how to change a function in a WordPress plugin, but let me show you a real world example from Easy Property Listings, a really great and customizable real estate plugin. My client wanted to remove the <a> element from featured image on single property listing page. The thing was that if you click on that image, it would take you to that same post anyway, so having a link there was a redundant thing to have.

So let’s have a look at the function which renders featured image:

Why are there two actions? Because they are hooked in different parts of the plugin. So the first thing we need to do (inside functions.php or your custom functions plugin) is to remove the action. Make sure you use the same priority values. So depending on where you want to change this (on which template), you can go with:

And now the next thing is to create your own function, which will in our case be only slightly altered above function:

And then hook this custom function into epl_property_featured_image() hook by doing this:

In the end, if asking yourself in what way this function outputs on that specific template, it is because the template is using do_action() hook by calling whatever is hooked on that action:

This is one of the great examples on how action hooks can be used by plugin developers to allow easy plugin modifications without having to worry about future updates.