Created
March 21, 2017 19:49
-
-
Save theMikeD/bab696dbee418af270ff25286e71ce1c to your computer and use it in GitHub Desktop.
To see info on a page in WP source.
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 | |
add_action( 'wp_head', 'cnmd_debug_insert_template_info_into_src' ); | |
/** | |
* Insert the template in use and the page ID into <head> of the document src. | |
*/ | |
function cnmd_debug_insert_template_info_into_src() { | |
global $template; | |
global $post; | |
// Get the path part | |
$url = parse_url($template, PHP_URL_PATH); | |
// Split on / | |
$surl = explode('/',$url); | |
// Template file is the last one | |
$tmpl = $surl[count($surl)-1]; | |
// Make the full path normal, the template bold | |
$out = "\n<!------------------------------------------------------------\n\n" . | |
" Template: $tmpl\n" . | |
" Path: $url\n" . | |
" Page ID: " . get_the_ID() . "\n" . | |
" Page Type: " . cnmd_debug_get_wp_conditionals() . "\n\n" . | |
"---------------------------------------------------------------->\n\n"; | |
echo $out; | |
} | |
/** | |
* Gets all WP conditionals as text for use in debugging statements | |
* @return string | |
*/ | |
function cnmd_debug_get_wp_conditionals() { | |
$type = ""; | |
if ( is_home() ) { $type .= "is_home "; } | |
if ( is_front_page() ) { $type .= "is_front_page "; } | |
if ( is_admin() ) { $type .= "is_admin "; } | |
if ( is_admin_bar_showing() ) { $type .= "is_admin_bar_showing "; } | |
if ( is_single() ) { $type .= "is_single "; } | |
if ( is_sticky() ) { $type .= "is_sticky "; } | |
if ( is_post_type_archive() ) { $type .= "is_post_type_archive "; } | |
if ( comments_open() ) { $type .= "comments_open "; } | |
if ( pings_open() ) { $type .= "pings_open "; } | |
if ( is_page() ) { $type .= "is_page "; } | |
if ( is_page_template() ) { $type .= "is_page_template "; } | |
if ( is_tag() ) { $type .= "is_tag "; } | |
if ( is_tax() ) { $type .= "is_tax "; } | |
if ( is_author() ) { $type .= "is_author "; } | |
if ( is_date() ) { $type .= "is_date "; } | |
if ( is_year() ) { $type .= "is_year "; } | |
if ( is_day() ) { $type .= "is_day "; } | |
if ( is_time() ) { $type .= "is_time "; } | |
if ( is_new_day() ) { $type .= "is_new_day "; } | |
if ( is_archive() ) { $type .= "is_archive "; } | |
if ( is_search() ) { $type .= "is_search "; } | |
if ( is_404() ) { $type .= "is_404 "; } | |
if ( is_paged() ) { $type .= "is_paged "; }; | |
if ( is_attachment() ) { $type .= "is_attachment "; } | |
if ( is_singular() ) { $type .= "is_singular "; } | |
if ( is_main_query() ) { $type .= "is_main_query "; } | |
return $type; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment