I use a very modern and fully-featured theme that has a lot of custom functions. Something like Avada, Enfold, etc.

There's this function called medigroup_mikado_custom_breadcrumbs that's being called at wp-content/themes/mytheme/framework/modules/title/title-functions.php and I'm trying to filter it in functions, with this code:

function custom_debug_breadcrumb($breadcrumb) {
    $breadcrumb = "test";
    return $breadcrumb;
add_filter('medigroup_mikado_custom_breadcrumbs', 'custom_debug_breadcrumb', 10);

However, no matter what I put on that function, it doesn't seem to run at all.

My question is, can I filter a function called by a theme? Only for knowledge purposes, what if it was a plugin? Can I only filter core?


Filters are one of the two types of Hooks.

They provide a way for functions to modify data of other functions.

You can filter any function that has applied a filter on it's variables during the function definition.

For example, in the get_bloginfo function, you would see a filter applied on it's output just before the output is returned:

$output = apply_filters( 'bloginfo', $output, $show );

The above apply_filters call means you can modify the output by defining a filter such as:

function wpse253559_define_filter( $output, $show ) {

    return 'altered';

add_filter( 'bloginfo', 'wpse253559_define_filter', 10, 2 );

This would alter the output of get_bloginfo to always return "altered" no matter what it's initial value is. You can read more on add_filter and apply_filters.



What you're trying to do is not filtering, but monkeypatching. You can't monkeypatch via filtering. A filter is a type of hook, an even with a name. Some filters have the same name as the functions that call them, but this is a coincidence/convention

If you want to modify what the function returns via a filter, that function needs to pass what it returns into a filter so that it can be modified. The equivalent of saying "I'm about to ship this, does anybody want to make any last minute changes?". If the function doesn't do this then it can't be done via filters without forking the codebase

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.