Created
November 26, 2018 10:00
-
-
Save Langmans/f571c94f2b00648dcce7e84582d437b7 to your computer and use it in GitHub Desktop.
gets the loaded php file within a wordpress theme
This file contains hidden or 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 | |
function get_loaded_theme_files() { | |
$sdir = realpath( get_stylesheet_directory() ) . DIRECTORY_SEPARATOR; | |
$tdir = realpath( get_template_directory() ) . DIRECTORY_SEPARATOR; | |
return array_filter( get_included_files(), function ( $file ) use ( $sdir, $tdir ) { | |
$r = realpath( $file ); | |
$d = dirname( $r ) . DIRECTORY_SEPARATOR; | |
if ( $d !== $sdir || $d !== $tdir ) { | |
return false; | |
} | |
$b = basename( $file ); | |
if ( in_array( $b, [ 'functions.php', 'header.php', 'footer.php' ] ) ) { | |
return false; | |
} | |
return true; | |
} ); | |
} | |
function get_loaded_theme_file() { | |
return array_shift( get_loaded_theme_files() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment