Writing to the Google Chrome console from PHP

Chrome Logger is a Google Chrome extension for debugging server side applications in the Chrome console.
Chrome Logger is a Google Chrome extension for debugging server side applications in the Chrome console.

This afternoon I finally got round to figuring out why my workaround for changing the Divi projects custom post type to anything you want had broken in Divi 2.5.

In the end it was deceptively simple. I’d set the priority values for the add_action($hook, $function_to_add, $priority) and remove_action($hook, $function_to_add, $priority) functions too low.

WordPress uses the priority value to determine in which order particular actions are run. The default value is 10. The higher the value, the later it will be executed.

While I was investigating this, it crossed my mind that it would be really useful if I could write values to the Google Chrome console in the same way that you can when writing and debugging JavaScript.

It turns out you can, using Chrome Logger plus the ChromePhp library.

With the Chrome Logger extension installed and enabled on the tab I wanted to write to, all I had to do was include the library and log some data. Like this:

Very useful. And as well as a library for PHP there are also libraries for

  • ColdFusion
  • Go
  • Java
  • .NET
  • Node.js
  • Perl
  • Python
  • Ruby

You can find details on the Chrome Logger website.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.