Send php errors to your Javascript console

Originally published on 24 March, 2021 by Jacob Stordahl

When working with WordPress themes, often it's handy to output php errors & responses to the Javascript console so they're easily accessible especially if you're debugging on a shared/ VPS server.

function debugToConsole($msg){
    echo "<script>console.log(".json_encode($msg).")</script>";
 }

If you define this function, whatever $msg you pass to it will be output to the browsers Javascript console!

© 2021 Jacob Stordahl | built with Steel