WordPress applies ltrim
on the $file
— ltrim( $file, '/' )
, so it becomes inc/template-tags.php
instead of /inc/template-tags.php
.
So within your filter callback, you should use:
if ( $file !== 'inc/template-tags.php' )
UPDATE
my child version has the adjustments
I don't know if you made adjustments to pluggable or non-pluggable function(s) in the template file, but as pointed by @JacobPeattie, you should consider extending parent theme functions like so:
For pluggable functions such as twentyseventeen_posted_on
, just copy the whole code and paste it in your functions.php
file. And then just make your adjustments.
Pluggable functions are defined like so, where the function is wrapped inside a conditional which checks whether a function with the same name already exists or not, and if not, the function is defined:
if ( ! function_exists( 'function_name' ) ) :
function function_name() {
...
}
endif;
For non-pluggable functions such as twentyseventeen_front_page_section
, follow the same steps above (copy the function code to your functions.php
file), but make sure to rename the function — e.g. my_theme_front_page_section
or my_twentyseventeen_front_page_section
.
And after you renamed the function, make sure to change the name in template files where the function is being called. For example, twentyseventeen_front_page_section
is being called in the front page (front-page.php
) template, so you'd change twentyseventeen_front_page_section( null, $i );
to my_theme_front_page_section( null, $i );
(if you renamed the function to my_theme_front_page_section
).
I could understand that it might be a hassle to do the renaming part, but particularly for pluggable functions, you don't need to override the template file using the parent_theme_file_path
filter (or similar filter). The function(s) you're trying to modify might also actually have filters you can simply hook into to customize/change the function output, so be sure to check that. :)
get_parent_theme_file_path()
for a reason. This is a signal that you shouldn’t be replacing the whole file in a child theme. If you want to replace template tags then you should copy the just the function into your child theme and modify it there (if it’s pluggable) or create a new function and then replace the original function by copying the template that it’s used in and replacing the original function call with a call to yours.