<?php
/**
* 現在のページのナビにclassを付与する関数
*
*/
function is_current( $uri = '' ) {
$uri = trim( $uri, '/' );
$request_uri = ( empty( $_SERVER['HTTPS'] ) ? 'http://' : 'https://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parse_url = wp_parse_url( $request_uri );
$path_array = explode( '/', $parse_url['path'] );
$tagert_path = current( array_slice( $path_array, -2, 1, true ) );
if ( $uri && strpos( $tagert_path, $uri, 0 ) !== false ) {
return true;
}
$tagert_path = trim( str_replace( '/index.php', '', $tagert_path ), ‘ / ’ );
if ( ! $uri && ! $tagert_path ) {
return true;
}
return false;
}
function echo_current( $uri = '' ) {
if ( is_current( $uri ) ) {
echo 'is-current';
};
}