Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print to console from a php file in wordpress

Tags:

php

wordpress

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.

like image 569
grabury Avatar asked Oct 21 '15 17:10

grabury


People also ask

Is there a way to print to console in PHP?

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.

How do I call a PHP script from WordPress?

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”.

How do I print from console log?

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.

How do I view PHP 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.


1 Answers

If you are thinking about the javascript console, you can not do this from PHP.

You have a few options you could choose from:

  • echo
  • var_dump
  • create a log file
  • xdebug

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.

like image 80
lshas Avatar answered Oct 20 '22 02:10

lshas