DEV Community

Cover image for Simple WP-CLI Commands That Make WordPress Easier
Muhammad Medhat
Muhammad Medhat

Posted on

Simple WP-CLI Commands That Make WordPress Easier

WP-CLI isn’t just for advanced developers.
Even for basic WordPress tasks, it can save time and reduce a lot of clicking around in the dashboard.

If you already know what WP-CLI is and how to install it, here are simple, everyday commands I use to manage WordPress sites faster.


1) Check Basic Site Info (First Thing I Run)

wp option get siteurl
wp option get home
wp core version
wp user list --fields=ID,user_login,roles
wp theme list --status=active
Enter fullscreen mode Exit fullscreen mode

When to use it:
Right after connecting to a server, or before doing any changes.

Why:
This gives you a quick picture of the site without opening wp-admin:

Which site URL you’re on

Which WordPress version is running

Who the users are (and their roles)

Which theme is active

It’s an easy way to make sure you’re in the right place and understand the setup before touching anything.

2) See Active Plugins

wp plugin list --status=active
Enter fullscreen mode Exit fullscreen mode

When to use it:
When a site is slow or acting weird and you want to know what’s running.

Why:
Much faster than opening the Plugins page in wp-admin.


3) Disable or Enable a Plugin

wp plugin deactivate plugin-slug
wp plugin activate plugin-slug
Enter fullscreen mode Exit fullscreen mode

When to use it:
A plugin causes errors, white screens, or conflicts.

Why:
You can fix problems even if wp-admin is broken.


4) Update WordPress Core

wp core update
Enter fullscreen mode Exit fullscreen mode

When to use it:
WordPress shows an update notification.

Why:
It’s quick, reliable, and avoids browser timeouts.


5) Update Plugins and Themes

wp plugin update --all
wp theme update --all
Enter fullscreen mode Exit fullscreen mode

When to use it:
Doing regular maintenance or security updates.

Why:
One command replaces many clicks.


6) Fix Permalink Problems

wp rewrite flush --hard
Enter fullscreen mode Exit fullscreen mode

When to use it:
Pages suddenly show 404 errors after changes.

Why:
Same as re-saving permalinks in settings, just faster.


7) Clear Cached Data

wp transient delete --all
wp cache flush
Enter fullscreen mode Exit fullscreen mode

When to use it:
You changed something but the site still shows old data.

Why:
Clears temporary stored values that cause confusion.


8) Enable Maintenance Mode

wp maintenance-mode activate
Enter fullscreen mode Exit fullscreen mode

Disable it when finished:

wp maintenance-mode deactivate
Enter fullscreen mode Exit fullscreen mode

When to use it:
Making quick updates or small migrations.

Why:
Stops visitors from seeing half-finished changes.


9) Create a New User

wp user create editor1 editor@example.com --role=editor --user_pass='Password123'
Enter fullscreen mode Exit fullscreen mode

When to use it:
You need to add a user quickly.

Why:
No forms, no waiting for email confirmations.


10) Reset a User Password

wp user update editor1 --user_pass='NewPassword123'
Enter fullscreen mode Exit fullscreen mode

When to use it:
Someone can’t log in and email isn’t working.

Why:
Instant fix without touching wp-admin.


11) List Pages or Posts

wp post list --post_type=page
Enter fullscreen mode Exit fullscreen mode

When to use it:
You want a quick overview of site content.

Why:
Faster than browsing multiple admin screens.


12) List Media Files (Attachments)

Media files in WordPress are stored as attachments, so you list them like this:

wp post list --post_type=attachment --fields=ID,post_title,guid --format=table
Enter fullscreen mode Exit fullscreen mode

When to use it:
After a migration or when uploads look wrong.

Why:
Gives you a clear list of media without opening the Media Library.


Important Note About wp media

You can’t use wp media list to list uploads.
That command does not exist in core WP-CLI.

👉 To list media → use attachments with wp post.

However, wp media is still very useful for managing media files.


Useful wp media Subcommands

  • Fix image rotation
  wp media fix-orientation
Enter fullscreen mode Exit fullscreen mode

When: Images look rotated after upload
Why: Automatically fixes orientation metadata

  • See registered image sizes
  wp media image-size
Enter fullscreen mode Exit fullscreen mode

When: You want to know which image sizes WordPress uses
Why: Helpful when working with themes or performance

  • Import media files
  wp media import image.jpg
Enter fullscreen mode Exit fullscreen mode

When: Uploading files in bulk or migrating content
Why: Faster than uploading through the browser

  • Regenerate thumbnails
  wp media regenerate
Enter fullscreen mode Exit fullscreen mode

When: After changing image sizes or switching themes
Why: Ensures images match the new settings

Easy way to remember:

List media → wp post (attachments)
Manage media → wp media


13) Quick Search & Replace (Safe Way)

wp search-replace 'http://oldsite.com' 'https://newsite.com' --dry-run
Enter fullscreen mode Exit fullscreen mode

When to use it:
After moving a site or changing domains.

Why:
Safely updates links without breaking data.
Always run with --dry-run first.


14) Check WordPress Core Files

wp core verify-checksums
Enter fullscreen mode Exit fullscreen mode

When to use it:
Something feels broken or suspicious.

Why:
Confirms WordPress core files are clean and unchanged.


15) Run a Small One-Time Check

wp eval 'echo get_bloginfo("name");'
Enter fullscreen mode Exit fullscreen mode

When to use it:
You just want to check or tweak something quickly.

Why:
Lets you use WordPress functions without editing files.


A Small Note on Custom Post Types

I often use WP-CLI for Custom Post Types too, mainly to keep things fast and consistent. I’ll cover that workflow in a separate article.


Final Thoughts

WP-CLI isn’t only for advanced developers.
Even simple tasks—updates, users, plugins, media—are easier once you get used to it.

If you already know WordPress, WP-CLI is just another tool that makes daily work smoother and less annoying.

Top comments (0)