Scott McDaniel (EE MVE )
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:
How can I do that without having to worry about updating every time my theme updates?
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
}
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
}
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?
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/con fig.php file...
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.
Overrideable functions will live inside a wrapper... Something like this in your config-events-calendar/con
if ( ! function_exists ( 'my_function' ) ) {
function my_function() {
// Contents of your function here.
}
}
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.
ASKER
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 TRIALMembers 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.
Correct way to do this is look into the config-events-calendar/con
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.