I'm build a custom Wordpress theme using get_template_part to call tiny bits of code. I have file called "masthead.php" that is called using this code:
<?php get_template_part( 'masthead' ); ?>
This works as expected. However, I would like to create some kind of file hierarchy inside my theme's folder. For example, if there's a file called "custom-masthead.php" use that file first but if the file does not exists, then use "masthead.php".
Is this something that can be accomplished?
Following @sabreuse's code I'm trying to make things a little bit more complicated. I would like to print the theme's folder name instead of the $name variable so the folder's name is my main variable before falling into the fallback. I tried this code:
<?php $theme_name = wp_get_theme(); get_template_part( 'masthead', 'echo $theme_name->Template;' ); ?>
But this doesn't seem to work. Maybe it's not possible?
Got it working:
<?php $my_theme = wp_get_theme(); get_template_part( 'masthead', $my_theme->Template ); ?>
Thanks a lot!