Change parent theme file function in child themes functions.php

Filters are for modifying the data, but actions are like bus stops where you can attach your functions to theme and they will be run when the script reaches an specific state.

To use any of the above, they must be first declared somewhere. Let’s take a look at this example from the codex page of apply_filters:

// Function that modifies the data
function example_callback( $string, $arg1, $arg2 ) {
    // (maybe) modify $string
    return $string;
}
// The filter used by user
add_filter( 'example_filter', 'example_callback', 10, 3 );

// Declaration of the filter by the person who 
$value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );

Now as you can see, the filter is declared and given a name by using $data = apply_filters( ... ). Then, somewhere else in the code it is called by using add_filter( ... ). So, if you have no filter declared attached to that data, there is no way you can filter that piece of data.

Now about your code. It seems like you grabbed that piece of code from a class. Most decent developers use pluggable functions when they write their code. It means, they define their classes and functions as follows:

if ( ! class_exists( 'some_class' ) {
    class some_class {
        // Class code here
    }
}

This allows the user to override that specific class or function, by simply defining it himself. Take a look at your code. If it’s following the same practice, then you can copy the class to your child theme’s functions.php file, and modify the parts of it you wish.

Leave a Comment