WordPress at a glance
Home Handbook WP-CLI Commands

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


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

You can specify global options and the following:

The code to execute, as a string.
Execute code without loading WordPress.


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

Source code of the commands