I have a php file which is part of a wordpress plugin. I need to debug an issue we are having. I want to find out what a variable's value is. How can I print the variable's value to console? echo or chrome or firefox extensions have been suggested. I couldn't get echo to output to console (echo “$variablename";
) and neither using the firephp extension for firefox.
The echo command is used in PHP to print any value to the HTML document. Use <script> tag inside echo command to print to the console.
Go to WordPress Admin Panel → Plugins → Add New. In the search area type “Insert PHP” and click Enter. In the search results choose the plugin called “Insert PHP” and click “Install Now”. Wait for the file to be downloaded to your host and then click “activate plugin”.
You should use the console. log() method to print to console JavaScript. The JavaScript console log function is mainly used for code debugging as it makes the JavaScript print the output to the console. To open the browser console, right-click on the page and select Inspect, and then click Console.
To start, open Google Chrome and go to any web page, right-click and choose Inspect to bring up Chrome's Developer Tools. The browser console will be one of the tabs in the Developer Tools. And you can test it out by writing the same JavaScript console.
If you are thinking about the javascript console, you can not do this from PHP.
You have a few options you could choose from:
For a quick check for a variables value I would use var_dump, it will also show you the data type of the variable. This will be output to the browser when you request the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With