How do i get to the console log in wordpress?

You can write a utility function like this:

function prefix_console_log_message( $message ) {

    $message = htmlspecialchars( stripslashes( $message ) );
    //Replacing Quotes, so that it does not mess up the script
    $message = str_replace( '"', "-", $message );
    $message = str_replace( "'", "-", $message );

    return "";
}

The you may call the function like this:

echo prefix_console_log_message( "Error Message: This is really a 'unique' problem!" );

and this will output to console like this:

Error Message: This is really a -unique- problem!

Notice the quotes replaced with "-". It is done so that message does not mess up your script as pointed by @Josef-Engelfrost

You may also go one step further and do something like this:

function prefix_console_log_message( $message, $type = "log" ) {

    $message_types = array( 'log', 'error', 'warn', 'info' );
    $type          = ( in_array( strtolower( $type ), $message_types ) ) ? strtolower( $type ) : $message_types[0];
    $message       = htmlspecialchars( stripslashes( $message ) );
    //Replacing Quotes, so that it does not mess up the script
    $message = str_replace( '"', "-", $message );
    $message = str_replace( "'", "-", $message );

    return "";
}

and call the function like this:

echo prefix_console_log_message( "Error Message: This is really a 'unique' problem!" , 'error');

It will output error in console.

How do i get to the console log in wordpress?

Debugging PHP can be a pain in WordPress. Add this handy code snippet to your theme’s functions.php file. The function will log PHP data to your browser’s console.

/**
 * @param ...$data
 *
 * @return void
 */
function my_console_log(...$data) {
    $json = json_encode($data);
    add_action('shutdown', function() use ($json) {
       echo "";
    });
}

// Example usage
my_console_log(['foo' => 'bar'], null, 1, 'hi');

Kevin Dees is a speaker, entrepreneur, blogger, and developer. He’s best known for his work in WordPress and podcasting for the retired SitePoint show. Kevin has developed sites for the brands Verizon, Denny’s, RIDGID, Michelin, and others. Currently, he is working on TypeRocket which powers over 10,000 professional websites and products internationally.

See all posts by Kevin Dees


How do i get to the console log in wordpress?
How to add PHP Console Log in Wordpress - Data

Tips
How do i get to the console log in wordpress?

Log PHP variables and arrays to the web console in your browser via JavaScript's console.log(). No browser extensions required.
Start tutorial with video following.

1. First Download "php-console-log.zip" Plugin to your Local Computer. (Click Download)

2. Then, Login to your "yourdomain.com/wp-admin" Dashboard.

How do i get to the console log in wordpress?

3. Then, Click on "Plugins" + "Add New" from left sidemenu of Dashboard.

How do i get to the console log in wordpress?

4. Now, Click on "Upload Plugin" button.

How do i get to the console log in wordpress?

5. Now, Browse "php-console-log.zip" Downloaded plugin from your computer, Where you downloaded php-console-log.zip According to Step – 1 Above then, click on "Install Now"

How do i get to the console log in wordpress?

6. Now, Click on "Active Plugin"

How do i get to the console log in wordpress?

7. Then, See left sidemenu. "PHP Console Log" folder is added on left sidemenu. Now, Click on "PHP Console Log" folder.

   Noted that: If you do not see "PHP Console Log" folder on left sidemenu then, see at left sidemenu "Settings" or "Tools".

8. Now you configure yourself oR Watch video tutorial below about PHP Console Log Configurtions and Settings or How to work "PHP Console Log" in your WordPress site.

9. Watch video Full Setup of PHP Console Log Tips \u0026 Tricks For Debugging WordPress PHP


9. Done...
If you have any question then, ask to us on Facebook Page
Guide
  1. Upload the plugin files to the /wp-content/plugins/php-console-log directory, or install the plugin through the WordPress plugins screen directly.
  2. Activate the plugin through the ‘Plugins’ screen in WordPress.
  3. You can find the help page in Plugins->PHP Console Log->Help for usage instructions.


How to access the console on WordPress?

Accessing the WordPress console via the URL /wp-admin By default, you just need to add /wp-admin to the end of your domain name's URL into the to access the WordPress console directly.

How do I log into PHP console?

Using json_encode function $js_code = 'console. log(' . json_encode($output, JSON_HEX_TAG) . You can call this function at the exact place you want to run the console_log that we just created above.