Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Created October 16, 2016 17:45
Show Gist options
  • Save X-Raym/72172d320d879e9b70433265aa05e305 to your computer and use it in GitHub Desktop.
Save X-Raym/72172d320d879e9b70433265aa05e305 to your computer and use it in GitHub Desktop.
Get WordPress Page Type
<?php
// http://wordpress.stackexchange.com/questions/83887/return-current-page-type
function get_page_type() {
global $wp_query;
$loop = 'notfound';
if ( $wp_query->is_page ) {
$loop = is_front_page() ? 'front' : 'page';
} elseif ( $wp_query->is_home ) {
$loop = 'home';
} elseif ( $wp_query->is_single ) {
$loop = ( $wp_query->is_attachment ) ? 'attachment' : 'single';
} elseif ( $wp_query->is_category ) {
$loop = 'category';
} elseif ( $wp_query->is_tag ) {
$loop = 'tag';
} elseif ( $wp_query->is_tax ) {
$loop = 'tax';
} elseif ( $wp_query->is_archive ) {
if ( $wp_query->is_day ) {
$loop = 'day';
} elseif ( $wp_query->is_month ) {
$loop = 'month';
} elseif ( $wp_query->is_year ) {
$loop = 'year';
} elseif ( $wp_query->is_author ) {
$loop = 'author';
} else {
$loop = 'archive';
}
} elseif ( $wp_query->is_search ) {
$loop = 'search';
} elseif ( $wp_query->is_404 ) {
$loop = 'notfound';
}
return $loop;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment