Image
Top
Navigation
July 1, 2014

A little help debugging complex WordPress themes

A little help debugging complex WordPress themes

Are you editing an already existing complex WordPress theme? Or perhaps you just purchased one from somewhere like Themeforest and it’s more advanced than you’re used to?

Well there’s a handy gist of code that you can throw in your header.php file of the theme to display what templates and files are being used for each page you view on the public side of things.

Usage:
I suggest you echo out the results in a HTML comment just to keep things looking good on the flip side.

<?php
 
 $included_files = get_included_files();
 $stylesheet_dir = str_replace( '\\', '/', get_stylesheet_directory() );
 $template_dir = str_replace( '\\', '/', get_template_directory() );
 
 foreach ( $included_files as $key => $path ) {
 
     $path = str_replace( '\\', '/', $path );
 
     if ( false === strpos( $path, $stylesheet_dir ) && false === strpos( $path, $template_dir ) )
         unset( $included_files[$key] );
 }
 
 var_dump( $included_files );

?>

Quick (Shortened) Usage

I prefer print_r() instead of var_dump() as it’s slightly more cleaner for this purpose

 <!--<?php $included_files = get_included_files();$stylesheet_dir = str_replace( '\\', '/', get_stylesheet_directory() );$template_dir = str_replace( '\\', '/', get_template_directory() );foreach ( $included_files as $key => $path ) { $path = str_replace( '\\', '/', $path ); if ( false === strpos( $path, $stylesheet_dir ) && false === strpos( $path, $template_dir ) ) unset( $included_files[$key] ); }print_r($included_files);?>-->

You can view the Github gist here https://gist.github.com/Braunson/6272471

The original cost post on Stack Overflow http://wordpress.stackexchange.com/a/89005/21131

Posted By

Categories

Code

quis efficitur. Aliquam nec et, id libero.