↑ ↓ select, Enter open, Esc close

Run PHP code in the WordPress context

Adjust the values, the command updates live
user@server
wp eval 'echo PHP_VERSION . " / WP " . get_bloginfo("version") . PHP_EOL;' --path=/var/www/vhosts/example.com/httpdocs

wp eval loads WordPress including plugins and runs the given PHP code. The example shows the PHP and WordPress versions as seen by the command line. Useful for testing functions, options or plugin code without creating a file.

Note: The code runs with full access to the installation. For multiple lines, there is the interactive console wp shell.

Also searched as

  • test php in wordpress context
  • call wordpress function from shell
  • which php version does wordpress use

Related one-liners

All in WP-CLI

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.