I have theme and in header.php and I found this templates (see attached screenshot). But there is no content directory in template directory. Even I searched for those files (header-private.php and header-public.php) but can't found. Then how those templates loading?
But there is no content directory in template directory.
Actually, with the following:
get_template_part( 'templates/content', 'header-private' );
get_template_part( 'templates/content', 'header-public' );
WordPress will search in the
templates folder for
content-header-public.php, and if found, it is loaded. Else, WordPress will attempt to load the
content.php file instead.
So WordPress (or
get_template_part()) will not search in a folder named
content, and instead, the "content" part in
templates/content means, "search for PHP files where the name begins with
content- in the
templates folder, and if none found, please load
content.php if it exists".
Other examples that might help:
// loads content.php get_template_part( 'content' ); // loads templates/content.php get_template_part( 'templates/content' ); // loads templates/content-foo-bar.php OR templates/content.php get_template_part( 'templates/content', 'foo-bar' ); // loads templates/content/foo-bar.php OR templates/content/foo.php // i.e. the function will now search in the "content" (sub-)folder get_template_part( 'templates/content/foo', 'bar' );
Check out the
get_template_part() documentation for more details about (using) the function.
Even I searched for those files (header-private.php and header-public.php) but can't found.
templates folder does not have these files:
content.php, then they might be in the parent theme if you are using a child theme, so try searching in the parent theme's
And it's because
get_template_part() will first search in the child and then parent theme, so the template that's loaded could be the one in the parent theme.
Technically though, it's actually
locate_template() which searches and loads the template, so you might also want to check the function's documentation.