Wednesday, 22 March 2017

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/

No comments:

Post a Comment