Created
April 26, 2012 14:45
-
-
Save zanematthew/2500075 to your computer and use it in GitHub Desktop.
Custom action for WordPress Template Redirect
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 | |
/** | |
* Determine if given templates exists if they do loads them | |
* based on the type of page being displayed. | |
* | |
* @uses is_single() | |
*/ | |
if ( ! function_exists( '_zm_template_redirect' ) ) : | |
function _zm_template_redirect( $params=array()){ | |
extract( $params ); | |
if ( is_single() ) { | |
if ( file_exists( $params['single'] ) ) { | |
load_template( $params['single'] ); | |
exit(); | |
} | |
} elseif ( is_post_type_archive('bmx-race-event') ) { | |
if ( file_exists( $params['archive'] ) ) { | |
load_template( $params['archive'] ); | |
exit(); | |
} | |
} elseif ( is_search() ) { | |
if ( file_exists( $params['search'] ) ) { | |
load_template( $params['search'] ); | |
exit; | |
} | |
} elseif ( is_tax() ) { | |
if ( is_array( $params['taxonomy'] ) ) { | |
foreach( $params['taxonomy'] as $taxonomy ){ | |
if ( file_exists( $taxonomy['template'] ) ) { | |
load_template( $taxonomy['template'] ); | |
exit; | |
} | |
} | |
} | |
if ( file_exists( $params['taxonomy'] ) ) { | |
load_template( $params['taxonomy'] ); | |
exit; | |
} else { | |
load_template( $params['taxonomy'] ); | |
exit; | |
} | |
} else { | |
if ( file_exists( $params['default'] ) ) { | |
load_template( $params['default'] ); | |
exit; | |
} | |
} | |
} | |
add_action( 'zm_template_redirect', '_zm_template_redirect', 1 ); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment