How to debug a WordPress theme


In WordPress theme development, or when editing an existing theme, it is often handy to know which template is used to display the current page. It is very easy to display the template within the page, by adding a small piece of code in your theme’s functions.php file. In this example, we will edit the functions.php file of a site using the Hellomouse theme. The current template is stored in the $template variable. Let’s create a function which loads and displays that variable.
function show_template() {
global $template;
print_r($template);
}
The vast majority of WordPress themes include the wp_head action hook, so in most cases we can safely call our function there. Let’s add the following right after our function:
add_action(‘wp_head’, ‘show_template’);
There!
function show_template() {
global $template;
echo ‘

‘;
print_r($template);
echo ‘

‘;
}
add_action(‘wp_head’, ‘show_template’);
Much better. The problem is that everyone visiting the website will be able to see the current
Source: https://managewp.org/articles/14660/how-to-debug-a-wordpress-theme


Source: https://williechiu40.wordpress.com/2017/03/22/how-to-debug-a-wordpress-theme/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s