1

I want to create a custom WP CLI command and I have read the documentation but I just don't understand for the life of me how this works.

Do I need to declare it before in my config file where they are gonna go?

Is it a PHP file? If so, I need to declare it put it anywhere inside my theme?

Thank you in advance.

1

You can put the PHP anywhere in your plugin, or a file that's included into your plugin, the same as you would any other code for extending any part of WordPress in a plugin. The only thing you need to do is check that WP_CLI exists before using any of the WP CLI API:

if ( defined( 'WP_CLI' ) && WP_CLI ) {
    // WP_CLI::add_command etc.
}
| improve this answer | |
  • Can I include this as a theme file and call it within functions.php? – Marco Berroca Nov 28 '19 at 16:58
  • Yes. It will work in themes too. – Jacob Peattie Nov 28 '19 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.