I’m creating my own theme framework, and I want to organize my code, separating the partials files from the pages.
But I want to do that and still use the native functions get_header()
, get_footer()
and get_sidebar()
.
How can I change this functions to look for the templates on the directory partials/
instead of the theme’s root directory?
Simple solution, use get_template_part()
.
For example:
get_template_part( 'partials/footer' );
Which would get the footer.php
inside the partials/
directory.
Another example:
get_template_part( 'partials/footer', 'home' );
Which would get the footer-home.php
inside the partials/
directory.
One more example:
get_template_part( 'partials/footer/blog' );
Which would get the blog.php
inside the partials/footer/
directory.