Created
November 17, 2015 19:57
-
-
Save StoyPenny/2de4ac52f230e0796b39 to your computer and use it in GitHub Desktop.
Detect the page type (post, archive, etc..) of WordPress content.
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 the wordpress page type | |
function detectPageType() { | |
if ( is_front_page() && get_option('show_on_front') == 'posts' ) { | |
$pageType = 'front-page'; | |
} else if ( is_home() && get_option('show_on_front') == 'page' ) { | |
$pageType = 'front-page'; | |
} else if ( is_attachment() ) { | |
$pageType = 'attachment'; // must be before is_single(), otherwise detects as 'single' | |
} else if ( is_single() ) { | |
$pageType = 'single'; | |
} else if ( is_page() ) { | |
$pageType = 'page'; | |
} else if ( is_author() ) { | |
$pageType = 'author'; | |
} else if ( is_category() ) { | |
$pageType = 'category'; | |
} else if ( is_tag() ) { | |
$pageType = 'tag'; | |
} else if ( function_exists('is_post_type_archive') && is_post_type_archive() ) { | |
$pageType = 'cp_archive'; // must be before is_archive(), otherwise detects as 'archive' in WP 3.1.0 | |
} else if ( function_exists('is_tax') && is_tax() ) { | |
$pageType = 'tax_archive'; | |
} else if ( is_archive() && ! is_category() && ! is_author() && ! is_tag() ) { | |
$pageType = 'archive'; | |
} else if ( function_exists('bbp_is_single_user') && (bbp_is_single_user() || bbp_is_single_user_edit()) ) { // must be before is_404(), otherwise bbPress profile page is detected as 'e404'. | |
$pageType = 'bbp_profile'; | |
} else if ( is_404() ) { | |
$pageType = 'e404'; | |
} else if ( is_search() ) { | |
$pageType = 'search'; | |
} else if ( function_exists('is_pod_page') && is_pod_page() ) { | |
$pageType = 'pods'; | |
} else { | |
$pageType = 'undefined'; | |
} | |
//echo 'Page Type: ' . $pageType; | |
return $pageType; | |
} | |
add_action('wp_head','detectPageType'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment