wp eval

Executes arbitrary PHP code.

Note: because code is executed within a method, global variables need to be explicitly globalized.

See also wp eval-file

Usage

wp eval {php-code} [--skip-wordpress]

You can specify global options and the following:

{php-code}
The code to execute, as a string.
[--skip-wordpress]
Execute code without loading WordPress.

Examples

# Display WordPress content directory.
$ wp eval 'echo WP_CONTENT_DIR;'
/var/www/wordpress/wp-content
# Generate a random number.
$ wp eval 'echo rand();' --skip-wordpress
479620423

Source code of the commands