tips
85 tips WordPress
One command, setting or habit at a time about WordPress: what it does, the line to copy and a caveat or two.
WP-CLI 59
-
Checks for a newer WP-CLI release and updates the phar after you confirm.
wp cli check-update -
Removes every theme except the active one, so old themes stop waiting for updates.
wp theme delete --all -
Shows the registered image sizes with width, height and crop, so you see what each upload costs.
wp media image-size -
Starts a quick local web server for a WordPress folder without Apache or nginx.
wp server --host=127.0.0.1 --port=8080 -
Approves all pending comments at once after you have checked the list.
wp comment list --status=hold --fields=comment_ID,comment_author,comment_content -
Runs the database upgrade step after new core files, with a dry run to check first.
wp core update-db --dry-run -
Opens an interactive MySQL client already logged in to the site's database.
wp db cli -
Creates a classic menu, adds links and assigns it to a theme location by script.
wp menu create "Main menu" -
Adds a category or tag to a post from the terminal and keeps the terms it has.
wp post term add 123 post_tag docker -
Publishes or drafts a post whose content comes from an HTML file on disk.
wp post create ./draft.html --post_title='Release notes' --post_status=draft --porcelain -
Prints the WordPress version plus database revision, TinyMCE version and package language.
wp core version --extra -
Checks whether one plugin is active and answers with exit code 0 or 1.
if wp plugin is-active woocommerce; then -
Gives a user one new role and removes the roles the account had before.
wp user set-role anna author -
Returns success when WordPress is installed, so a deploy script can branch on it.
if ! wp core is-installed 2>/dev/null; then -
Creates the same WXR file as Tools > Export, filtered by post type or date.
wp export --post_type=page --dir=exports -
Restores a database dump without typing the database user, password or host.
wp db import backup.sql -
Downloads a clean WordPress core in the language you want, without bundled themes and plugins.
wp core download --skip-content --locale=nl_NL -
Imports an export file from the terminal and creates or maps the post authors.
wp import site.wordpress.2026-11-30.000.xml --authors=create -
Prints the capabilities of a role so you can see what editors or shop managers may do.
wp cap list editor | sort -
Lists the terms of a taxonomy with ID, slug and how many posts use each one.
wp term list post_tag --fields=term_id,name,slug,count -
Generates wp-config.php with fresh salts while the password never appears on the command line.
wp config create --dbname=example_wp --dbuser=example --prompt=dbpass -
Lists every column of a table with its type, key and default value.
wp db columns wp_postmeta -
Lists every registered post type, including the hidden ones plugins add.
wp post-type list --fields=name,label,public,hierarchical -
Changes the permalink structure, and optionally the category and tag base, in one command.
wp rewrite structure '/%postname%/' -
Scans a plugin or theme for translatable strings and writes a POT file.
wp i18n make-pot . languages/my-plugin.pot -
Creates any number of placeholder posts or pages to test a theme or a query.
wp post generate --count=50 -
Makes a copy of the database with a new domain in it and leaves the live tables alone.
wp search-replace 'https://old.example.com' 'https://new.example.com' --export=moved.sql -
Defragments the WordPress database tables after a big cleanup using the credentials in wp-config.
wp db optimize -
Runs a PHP script file with WordPress fully loaded, passing extra arguments in $args.
$ids = get_posts( array( 'post_status' => 'draft', 'fields' => 'ids', 'numberposts' => -1 ) ); -
Prints the WordPress rewrite rules and lets you see which one matches a given URL.
wp rewrite list --format=csv -
Prints a single nested value from a WordPress option without dumping the whole array.
wp option pluck my_plugin_settings api timeout -
Lists every role on a WordPress site, including any that plugins added.
wp role list -
Adds images from a folder or URL to the WordPress media library without the browser.
wp media import /tmp/photos/*.jpg --post_id=123 --alt="Leiden in the snow" -
Puts an older version of a WordPress plugin back after an update breaks something.
wp plugin install my-plugin --version=2.4.1 --force -
Creates a WordPress child theme so your theme changes survive updates of the parent theme.
wp scaffold child-theme my-child --parent_theme=twentytwentyone --theme_name="My child" --activate -
Deletes every comment in the WordPress spam folder permanently with one WP-CLI command.
wp comment delete $(wp comment list --status=spam --format=ids) --force -
Switches WordPress plugin auto-updates on or off from the command line, per plugin or all.
wp plugin auto-updates status --all -
Turns WordPress maintenance mode on and off from the command line.
wp maintenance-mode activate -
Lists the available WordPress cron schedules, such as hourly and daily, with their intervals in seconds.
wp cron schedule list -
Lists, installs and updates the core language packs of a WordPress site from the command line.
wp language core install nl_NL -
Lists draft posts from the command line with the fields and output format you choose.
wp post list --post_status=draft -
Starts an interactive PHP console with WordPress loaded, to try functions and inspect data.
wp shell -
Runs a table check on the whole WordPress database using the credentials from wp-config.php.
wp db check -
Moving a WordPress site to a new domain means changing the old address everywhere in the database, and a wrong replace is painful to undo. WP-CLI lets you see the…
wp search-replace 'http://old.example' 'https://www.example.nl' --dry-run -
Checks the files of every installed plugin against WordPress.org and lists any that do not match.
wp plugin verify-checksums --all -
Compares your WordPress core files with the official list and reports anything changed or unexpected.
wp core verify-checksums -
Writes a compressed copy of your WordPress database without leaving an uncompressed dump on disk.
wp db export - | gzip > backup-$(date +%F).sql.gz -
Shows which object cache backend is active and clears it when stale values appear.
wp cache type -
Executes a snippet of PHP with WordPress loaded, without writing a plugin or a template.
wp eval 'echo get_option( "blogname" ), PHP_EOL;' -
Lists the size of every table in the WordPress database to find what makes it grow.
wp db size --tables --orderby=size --order=desc -
Lists the WordPress core updates that are available, split into major and minor versions.
wp core check-update -
Selects which site of a multisite network a WP-CLI command should run on.
wp plugin list --status=active --url=https://shop.example.com -
Prints the sites of a multisite network, either as a table or as plain URLs for scripts.
wp site list --fields=blog_id,url,registered --format=table -
Shows every scheduled WordPress task with its next run time and repeat interval.
wp cron event list -
Rebuilds the permalink rules, and the .htaccess file with --hard, to cure 404 errors on posts.
wp rewrite flush --hard -
Reads the stored site address and home address to find the cause of redirect loops.
wp option get siteurl -
Sets a new random password for a user without sending an email and prints it in the terminal.
wp user reset-password admin --skip-email --show-password -
Adds a user with a chosen role from the terminal and prints only the new ID.
wp user create anna [email protected] --role=editor --porcelain -
Lists only the plugins that have a newer version available, with installed and offered versions.
wp plugin list --update=available --fields=name,version,update_version
Config constants 12
-
Makes deleted media go to the trash first instead of disappearing with its files.
define( 'MEDIA_TRASH', true ); -
Tells WordPress you are developing a theme so theme.json edits show up immediately.
define( 'WP_DEVELOPMENT_MODE', 'theme' ); -
Puts new uploads in a folder of your choice, relative to the WordPress root.
define( 'UPLOADS', 'media' ); -
Keeps one set of edited image files instead of a new set every time you crop.
define( 'IMAGE_EDIT_OVERWRITE', true ); -
Sets the number of seconds between editor autosaves in WordPress.
define( 'AUTOSAVE_INTERVAL', 180 ); // Seconds -
Sets after how many days WordPress permanently deletes trashed posts, pages and comments.
define( 'EMPTY_TRASH_DAYS', 60 ); // 60 days -
Chooses whether WordPress installs only minor releases, all releases or no core updates by itself.
define( 'WP_AUTO_UPDATE_CORE', 'minor' ); -
Marks a WordPress site as local, staging or production so plugins and code can behave differently.
define( 'WP_ENVIRONMENT_TYPE', 'staging' ); -
Writes WordPress errors to a log file while hiding them from visitors on the page.
define( 'WP_DEBUG', true ); -
Enables the advanced-cache drop-in that page caching plugins use to answer requests before WordPress loads.
define( 'WP_CACHE', true ); -
Sets how much PHP memory WordPress asks for, one value for the front end and one for the admin.
define( 'WP_MEMORY_LIMIT', '256M' ); -
Removes the code editors from the wordpress admin menu so admins cannot edit PHP in the browser.
define( 'DISALLOW_FILE_EDIT', true );
Debugging 8
-
Sends the recovery mode link to a developer address instead of the site admin email.
define( 'RECOVERY_MODE_EMAIL', '[email protected]' ); -
Prints every PHP error and the steps WP-CLI takes while loading the site.
wp plugin list --debug -
Checks whether WP-Cron is switched off or cannot call itself over HTTP.
wp cron test -
Switches off the friendly critical error page so you see the actual PHP error.
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); -
Makes WordPress load readable, unminified core scripts and styles so browser errors are traceable.
define( 'SCRIPT_DEBUG', true ); -
Writes the WordPress debug log to a chosen path, which can be outside the public web folder.
define( 'WP_DEBUG', true ); -
Fetches the REST API index and lists the route namespaces, including those added by plugins.
curl -s https://example.com/wp-json/ | jq '.namespaces' -
Stores each database query with its runtime and calling function for finding slow queries.
define( 'SAVEQUERIES', true );
Admin settings 2
-
Explains the Settings > Media checkbox that sorts uploads into dated folders.
wp option get uploads_use_yearmonth_folders -
Asks search engines not to index a WordPress site, without blocking anyone from visiting it.
wp option get blog_public
Hardening 2
-
Forces the login page and admin onto HTTPS and explains the redirect loop behind a proxy.
define( 'FORCE_SSL_ADMIN', true ); -
Blocks outgoing HTTP requests from WordPress except to hosts you put on an allowlist.
define( 'WP_HTTP_BLOCK_EXTERNAL', true );
REST API 2
-
Creates a revocable password for one script or app to call the REST API.
wp user application-password create anna backup-script --porcelain -
Makes the WordPress REST API return only the fields you list, so responses are smaller and faster.
curl "https://example.com/wp-json/wp/v2/posts?_fields=id,title,link"
Nothing in this filter yet.