Overwrite template-tags.php in child theme

I would like to overwrite some content which is located in (inc/) template-tags.php file on parent theme.

Content need to be changed is in function footer_content_widget_area in template-tags.php file and that function is called on functions.php:

add_action( 'page_widgets', 'footer_content_widget_area' );

Topic child-theme templates themes Wordpress

Category Web


In functions.php child theme include template-tags.php from parent theme:

require_once get_theme_file_path( '../parent-theme/inc/template-tags.php' );

In the child theme template-tags.php remove parent action and add the child action replacing it:

remove_action( 'tag', 'parent-function', 0 );
add_action( 'tag', 'new-child-function', 10 );

As long as you have a child-theme setup correctly then you just allow the child-theme to replace the parent-theme template by placing the template file in the same location.

So based on the location that you mention in your question you would simply place your edited copy of the template-tags.php in the location child-theme/inc/

the wordpress way of things is explained in the Template_Hierarchy (https://developer.wordpress.org/themes/basics/template-hierarchy/).

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.