Created
February 6, 2015 20:37
-
-
Save jesgs/f80b2be5b636493834b0 to your computer and use it in GitHub Desktop.
WordPress locate_template example
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 | |
/** | |
* Theme view template example using locate_template | |
* | |
* @return string | |
*/ | |
function my_theme_template() | |
{ | |
// do view related stuff | |
$date = date('M j Y'); | |
$template_content = ""; | |
$found_template = locate_template(array('my-template.php')); | |
if (!$found_template) | |
return $template_content; // return empty if not found | |
ob_start(); | |
require_once $found_template; | |
return ob_get_clean(); | |
} |
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 | |
/** | |
* my-template.php | |
*/ | |
?> | |
Today's date: <?php echo $date; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment