Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created November 26, 2018 10:00
Show Gist options
  • Save Langmans/f571c94f2b00648dcce7e84582d437b7 to your computer and use it in GitHub Desktop.
Save Langmans/f571c94f2b00648dcce7e84582d437b7 to your computer and use it in GitHub Desktop.
gets the loaded php file within a wordpress theme
<?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