Default WordPress Theme File Locations
In a minimal WordPress theme, you will often find only style.css and index.php. When your main template calls get_header() or get_footer(), it is easy to assume these functions search for header.php and footer.php inside the same directory as index.php. While this is true by default, understanding exactly how the lookup process works prevents confusion when customizing themes or debugging missing templates.
When a theme loads, WordPress initializes the template hierarchy based on the active theme folder. The core functions get_header() and get_footer() do not hardcode a specific filename; instead, they rely on the standard naming convention for theme parts. By default, the system looks for files named header.php and footer.php in the root of the active theme directory. This means if your theme folder is located at /wp-content/themes/my-theme/, WordPress will attempt to load /wp-content/themes/my-theme/header.php and /wp-content/themes/my-theme/footer.php.
If those files do not exist, or if you have placed them in a subdirectory like includes/, the functions will fail silently in older versions of WordPress or throw errors depending on the configuration. In modern WordPress installations, calling get_header() when the file is missing often triggers a PHP warning or error notice in the debug log, but it does not automatically create a fallback behavior within the theme folder itself.
To verify where these files are expected to live during development, you can inspect the theme directory structure directly. Using a command-line approach on Linux or macOS, you can list the contents of your active theme:
ls -la wp-content/themes/my-theme/
You will likely see index.php, style.css, and possibly functions.php. If you have not created header.php or footer.php yet, the functions will still execute because they are looking for specific filenames in that exact location. If you subsequently create a custom header and move it to a subdirectory like parts/header-custom.php, simply renaming your files is insufficient. You must also modify the theme code to point to the new path, or define custom template paths in functions.php.
Consider this scenario where you want to separate your core structure from specialized headers. In functions.php, you can override the default locations:
add_filter('theme_location_header', function($path) {
return 'parts/header-custom.php';
});
However, note that custom filters like the one above are not part of the standard WordPress API and may require specific plugin support or custom coding to work as intended across different versions. The most reliable method remains adhering to the default naming convention unless you have a compelling reason to deviate.
A common pitfall occurs when developers assume that creating header.php inside a child theme will automatically override the parent theme's header if the parent also has one. While child themes inherit files from parents, the lookup order prioritizes the active theme folder first. If your child theme lacks header.php, WordPress falls back to the parent theme's version only if the child theme does not explicitly define a different location or if the parent file is included via the standard hierarchy logic.
When building themes from scratch, it is best practice to include header.php and footer.php in the root of your theme directory immediately, even if they are empty at first. This ensures that calls to get_header() and get_footer() function correctly without triggering PHP errors or relying on default WordPress defaults that might vary slightly between versions.
If you are migrating an existing site or working with a theme framework that uses custom template paths, always verify the file locations against the framework's documentation. Some frameworks expect these files in specific subdirectories like includes/ or templates/, and deviating from their expected structure can break the layout entirely.
For those managing multiple themes simultaneously, remember that WordPress loads files relative to the currently active theme directory. Switching themes without updating your code references will immediately change which header and footer are rendered, potentially exposing you to security risks if you inadvertently load a version of header.php containing outdated or vulnerable code.