Last active
August 29, 2015 14:13
-
-
Save inc2734/03d23ce33eec770ec784 to your computer and use it in GitHub Desktop.
WordPressで一番親のディレクトリ名を取得する。サブディレクトリインストール型対応。
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 | |
/** | |
* get_second_directory | |
*/ | |
function get_second_directory() { | |
if ( $_SERVER['REQUEST_URI'] ) { | |
$home_url = home_url(); | |
$home_url = explode( '/', $home_url ); | |
$REQUEST_URI = $_SERVER['REQUEST_URI']; | |
$REQUEST_URI = preg_replace( '/^(.*)?\?.*$/', '$1', $REQUEST_URI ); | |
$REQUEST_URI = trim( $REQUEST_URI, '/' ); | |
$directories = explode( '/', $REQUEST_URI ); | |
$over = 0; | |
if ( count( $home_url ) >= 4 ) { | |
$over = count( $home_url ) - 3; | |
} | |
foreach ( $directories as $directory ) { | |
if ( $directory ) { | |
if ( $over ) { | |
$over --; | |
continue; | |
} | |
return $directory; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment