Here are a few WP-CLI tricks and tips that might be useful:
Aliases
Use aliases to make commands shorter and easier to remember. You can use the --alias=<alias>
flag when defining a command to specify a shorter alias for the command.
For example, if you use a command wp my-command
:
wp my-command
you could define a command with the alias wp my-command --alias=mc
wp my-command --alias=mc
and then use wp mc
to run the command instead of wp my-command
.
wp mc
Skip flag
Use the --skip-plugins
and --skip-themes
flags to skip loading plugins and themes when running WP-CLI commands. This can be useful if you are troubleshooting an issue with a plugin or theme and need to temporarily disable it.
Here are some examples of how you can use the --skip-plugins
and --skip-themes
flags when running WP-CLI commands:
- To skip loading plugins when running a WP-CLI command, use the
--skip-plugins
flag:
wp --skip-plugins <command>
- To skip loading themes when running a WP-CLI command, use the
--skip-themes
flag:
wp --skip-themes <command>
- To skip loading both plugins and themes when running a WP-CLI command, you can use both flags:
wp --skip-plugins --skip-themes <command>
For example, if you want to skip loading plugins and themes when running the wp plugin list
command, you could use the following command:
wp --skip-plugins --skip-themes plugin list
This would show a list of all installed plugins, but would not load any plugins or themes while running the command.
Prompt
Use the --prompt
flag to interactively prompt the user for input when running a command. This can be useful if you want to create a command that asks the user for specific input.
Get & Set
Use the wp option get
and wp option set
commands to get and set options in the WordPress database. This can be useful for modifying site settings or debugging issues.
These are just a few examples of the many things you can do with WP-CLI. For more information and additional tips, you can check out the WP-CLI documentation.