Open WP Admin From The Command Line
I use WP-CLI for pretty much everything these days. And since I am more and more working from a Linux system and thus practically living on the command line, I wanted to have a quick way to open WP Admin right there.
I added the following shell function to my bash config file, .bashrc in my case:
wpadmin() {
local site="${1:-}"
(open "$(wp $site option get siteurl --skip-plugins)/wp-admin" 2>/dev/null &)
}
It works with and without WP-CLI aliases, so I can use it both locally and for remote sites.
A couple of notes:
- Use
xdg-openinstead ofopen, if that is not available on your system - The
--skip-pluginsflag is optional, but speeds up the process for some of my sites - I know about wp-cli-login-command, but I wanted something simpler that works for all sites, and I’m usually already logged in anyway
- Make sure to run
source .bashrcafter you added the function or open a new terminal - Update: Claudio pointed out that there is also wp admin. (I am not sure why this never came up, when I was searching for this functionality…) However, the command is not part of core WP-CLI and has to be installed as an additional package.
I hope you find this useful!