Link to home
Start Free TrialLog in
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )Flag for United States of America

asked on

Modifying Wordpress Child Theme Functions.php file

I'm using a Child theme in my Wordpress site, and I want to override a line in my parent theme's Functions.php file:

If( ! current_theme_supports( 'deactivate_tribe_events_calendar' ) )
{
    // Below was removed to make single events look better:
	require_once( 'config-events-calendar/config.php' );			//compatibility with the Events Calendar plugin
}

Open in new window

I want to comment out the "require_once" line. I tried adding that to my child's Functions.php line:

If( ! current_theme_supports( 'deactivate_tribe_events_calendar' ) )
{
    // Below was removed to make single events look better:
    //	require_once( 'config-events-calendar/config.php' );			//compatibility with the Events Calendar plugin
}

Open in new window

But when the site loaded it ignored that and obviously used the line from the parent theme.

How can I do that without having to worry about updating every time my theme updates?
Avatar of David Favor
David Favor
Flag of United States of America image

The entire point of Child themes is so you never touch any Parent theme code, because next Parent theme update can destroy any Parent theme coding changes.

Correct way to do this is look into the config-events-calendar/config.php file + override any overridable functions.

If the function you require overriding has no override facility, then contact the theme developer to add this facility to their theme.

This way, you ensure your site survives all Parent theme updates.
Avatar of Scott McDaniel (EE MVE )

ASKER

Exactly, which is why I want to make the change in my child theme and not the parent. I'm not sure how to determine if a function is overrideable. How would I do that?


Ah... I missed this in your question...

Overrideable functions will live inside a wrapper... Something like this in your config-events-calendar/config.php file...

if ( ! function_exists ( 'my_function' ) ) {
    function my_function() {
        // Contents of your function here.
    }
}

Open in new window


This says... "if my_function() already has been defined, skip defining it again".

So if you define my_function() in your Child theme, this will override (take precedence) over your Parent theme's my_function() definition.

If you find a function you need to override, which doesn't currently allow overriding, just open a ticket with the developer.

Since this is a small amount of work, most developers will make any function overridable, based on anyone's request.

That makes sense. So, based on your comment, the code block I showed in my original posting is not overrideable?


This is in the EventsCalendar plugin, which is heavily used it would seem. Don't know if that makes a difference as to whether the dev will make that overribeable.

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.