template-tags.php in WordPress Child Theme
Style.css and functions.php files are normally modified in WordPress child theme, we can find lots of example about how to do on them. However, when we had a chance to modify template-tags.php in child theme, we spent some time to find solution.
template-tags.php like functions.php, there are some functions in the file. We added a function using common way to replace the same function in parent theme:
if ( ! function_exists('pacify_posted_on') )
{
function pacify_posted_on() {
….
…
}
}
However, the child function did not work.We thought the problem came from our code, but it was not actually.
Finally, we found that if we would have to use template-tags.php in child theme, we should give a right folder direction in functions.php file. So for our case, we put the following line at first line in our child functions.php file:
<?php require get_stylesheet_directory() . '/inc/template-tags.php'; ?>
Then our child template-tags.php worked.
Please note:
get_stylesheet_directory() points to your child theme’s directory (not the parent theme’s directory);
get_template_directory() points to the parent theme directory.
Please read WordPress development document here.