admin管理员组

文章数量:1122846

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' );

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' );
Share Improve this question edited Mar 13, 2017 at 14:38 Ethan Rævan 4,0295 gold badges27 silver badges55 bronze badges asked Mar 13, 2017 at 14:12 Roger WayneRoger Wayne 2236 silver badges13 bronze badges 2
  • How does the parent theme load the file template-tags.php? – Milo Commented Mar 13, 2017 at 16:25
  • It is loaded in custom function in functions.php. – Roger Wayne Commented Mar 13, 2017 at 18:45
Add a comment  | 

2 Answers 2

Reset to default 0

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/).

本文标签: Overwrite templatetagsphp in child theme