As a WordPress developer, sometimes you use echo, var_dump, print or print_r to know the type and value of a variable in PHP. But this process is very slow as it takes 4 steps to retrieve the result.
But the problem occurs when you do not know the type of a variable and use echo for displaying the value of a object. Here comes PHP Debug Bar. It can save you time and increase your productivity. Some of its features are:
If you include it with from their sample example, you may face some issues like below:
So, follow the steps below to add PHP Debug Bar in WordPress Installation. Make sure you have composer installed on your system.
`
<?php
use DebugBar\StandardDebugBar;
if( ! WP_DEBUG ) return;
require ABSPATH . 'vendor/autoload.php';
$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer();
$debugbarRenderer->setOptions( array( 'base_url' => site_url('/vendor/maximebf/debugbar/src/DebugBar/Resources/') ) );
$debugbarRenderer->setIncludeVendors(false);
add_action('wp_head', function() {
global $debugbarRenderer;
echo $debugbarRenderer->renderHead();
});
add_action('wp_footer', function() {
global $debugbarRenderer;
echo $debugbarRenderer->render();
});
Thats all. Happy coding.