Last active
March 14, 2023 23:16
-
-
Save mikeott/d249c4e61e7026d7265b1c765329f8ee to your computer and use it in GitHub Desktop.
WordPress: Check if a custom template exists in the theme folder, if not, then use the plugin template file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// The template | |
$template = 'my-custom-script.php'; | |
// If a template file exists in the theme folder, use it. | |
if ( $theme_file = locate_template( array( 'my-custom-files/' . $template ) ) ) { | |
include(get_template_directory() . '/my-custom-files/' . $template); | |
} else { // Otherwise, use the plugin template file. | |
include(plugin_dir_path( __FILE__ ) . '/templates/' . $template); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment