Developers
Magic Link WP-CLI: Generate Login Links From the Terminal
Need to create a magic login link without opening the WordPress dashboard — from a script, a deploy step, or an SSH session? Magic Link ships a free WP-CLI command that generates passwordless login links straight from the terminal. Run wp magic-link generate <user> to print a link, add --send to email it, and --count to make several at once. The command is free; the --redirect-to flag is a PRO addition.
What is the Magic Link WP-CLI command?
wp magic-link generate is a WP-CLI subcommand that creates a magic login link for a WordPress user from the command line. It is useful when you would rather script link creation than click through the admin — automated onboarding, support tooling, or a quick link during a deploy.
wp magic-link generate <user>
<user> accepts any of:
- a user ID —
42 - an email address —
alex@company.com - a login (username) —
alex
Options
| Option | What it does | Default | Tier |
|---|---|---|---|
--count=<n> |
Generate n links at once |
1 |
Free |
--send |
Email the link to the user instead of only printing it | off | Free |
--redirect-to=<url> |
Send the user to a specific URL after login | site home | PRO |
PRO feature
--redirect-to requires Magic Link PRO. On the free plugin the command still runs, but the redirect option is ignored and users land on the default destination. See Free vs PRO features and Redirect users after login.
Examples
Generate a single link for a user by email:
wp magic-link generate alex@company.com
Generate a link by user ID and email it to them:
wp magic-link generate 42 --send
Generate three links for a username:
wp magic-link generate alex --count=3
Email a link to the admin account:
wp magic-link generate admin --send
Redirect the user to a specific page after login (PRO):
wp magic-link generate alex@company.com --redirect-to=https://example.com/account
When to use the command line
- Scripts and automation. Create links from cron jobs, deploy pipelines, or provisioning scripts without a browser.
- Support and admin. Generate a working link for a user over SSH when you are already on the server.
- Bulk one-offs. Use
--countto produce several links in a single call.
Conclusion
The free wp magic-link generate command creates passwordless login links from the terminal for any user identified by ID, email, or username, with --count to make several and --send to email them; --redirect-to adds a landing URL in PRO. It is the fastest way to script link creation outside the dashboard. To create links from other systems over HTTP instead, see the REST API.
FAQs
Is the Magic Link WP-CLI command free?
Yes. The wp magic-link generate command ships with the free Magic Link plugin, including the --count and --send options. Only the --redirect-to flag, which sets where a user lands after logging in, requires Magic Link PRO. On the free plugin the command runs normally but ignores that flag.
How do I email the generated link to the user?
Add the --send flag: wp magic-link generate alex@company.com --send. Instead of only printing the link to the terminal, Magic Link emails it to the user's WordPress account email, using the same delivery and branding as links generated in the admin. Without --send, the command prints the link for you to copy.
Can I identify the user by email or username instead of ID?
Yes. The <user> argument accepts a numeric user ID, an email address, or a login (username) interchangeably — wp magic-link generate 42, wp magic-link generate alex@company.com, and wp magic-link generate alex all work. Magic Link resolves whichever form you pass to the matching WordPress user.
How do I generate several links at once?
Use --count=<n>, for example wp magic-link generate alex --count=3 to create three links for that user in a single call. The default is 1 when you omit the flag. Combine it with --send if you also want each link emailed rather than printed.
Can I set where the user goes after logging in?
Yes, with Magic Link PRO. Add --redirect-to=<url>, for example --redirect-to=https://example.com/account, to send the user to a specific page after the link logs them in. This option requires PRO; on the free plugin it is ignored and users land on the default destination.