WP-CLI commands, key hooks and wp-config constants, and a baseline hardening checklist for admins running WordPress in production.
| Category | Command | Description |
|---|---|---|
| Core | wp core download | Downloads WordPress core files into the current directory. |
| Core | wp core install --url=<url> --title=<title> --admin_user=<user> --admin_password=<pass> --admin_email=<email> | Runs the famous 5-minute install non-interactively. |
| Core | wp core update | Updates WordPress core to the latest version. |
| Core | wp core version | Prints the current WordPress version. |
| Plugins | wp plugin list | Lists installed plugins with status, version, and update availability. |
| Plugins | wp plugin install <slug> --activate | Installs a plugin from the WordPress.org repo and activates it. |
| Plugins | wp plugin update --all | Updates every plugin with an available update. |
| Plugins | wp plugin deactivate --all | Deactivates every active plugin at once — the fastest way to isolate a white-screen error. |
| Themes | wp theme list | Lists installed themes and which one is active. |
| Themes | wp theme activate <slug> | Switches the active theme. |
| Database | wp db export backup.sql | Exports the database to a SQL file. |
| Database | wp db import backup.sql | Imports a SQL file into the site's database. |
| Database | wp search-replace 'old.com' 'new.com' | Safely rewrites a domain/URL across all tables, including serialized PHP data. |
| Database | wp db optimize | Runs OPTIMIZE TABLE across the database to reclaim space and defragment. |
| Users | wp user list --role=administrator | Lists all users with the administrator role. |
| Users | wp user update <id> --user_pass=<newpass> | Resets a user's password directly — the standard "locked out of wp-admin" fix. |
| Users | wp user create <login> <email> --role=administrator | Creates a new admin user from the command line. |
| Maintenance | wp cache flush | Flushes the object cache (works with Redis/Memcached backends too). |
| Maintenance | wp rewrite flush | Regenerates permalink rewrite rules — fixes most 404-on-post-URL issues. |
| Maintenance | wp transient delete --all | Clears every transient — useful when cached data has gone stale or corrupt. |
| Maintenance | wp cron event run --all | Manually fires every due WP-Cron event — useful for debugging scheduled tasks. |
| Security | wp config set WP_DEBUG true --raw | Toggles debug mode in wp-config.php from the CLI. |
| Security | wp option get siteurl | Reads any option from wp_options — pair with wp option update to fix a wrong site URL without touching wp-admin. |
Common Hooks & Filters
Init & Setup
Content
Auth & Users
REST & Admin
wp-config.php Constants
WP_DEBUG
Enables PHP error reporting to the debug log. Pair with WP_DEBUG_LOG and WP_DEBUG_DISPLAY to keep errors out of the live page.
WP_MEMORY_LIMIT
Raises the PHP memory ceiling for WordPress specifically, independent of the server's own php.ini value.
DISALLOW_FILE_EDIT
Removes the theme/plugin file editor from wp-admin — a standard hardening step.
WP_AUTO_UPDATE_CORE
Controls automatic core updates: true for all, false for none, or 'minor' for security releases only.
FORCE_SSL_ADMIN
Forces wp-admin and wp-login.php to load over HTTPS even if the rest of the site doesn't.
WP_POST_REVISIONS
Caps how many revisions are kept per post — set a number (or false) to stop unbounded database growth.
Rotate the security keys
Regenerate the AUTH_KEY/SECURE_AUTH_KEY/etc. block in wp-config.php from the official secret-key API whenever a breach is suspected — this invalidates every existing session cookie.
Kill the "admin" username
Create a new administrator with a non-guessable login, reassign content with wp user delete 1 --reassign=<new-id>, then delete the default account.
Disable XML-RPC if unused
XML-RPC is a common brute-force and pingback-flood vector. Block xmlrpc.php at the web server level unless Jetpack or a mobile app depends on it.
Automate backups off-server
Schedule wp db export plus a full file sync to remote storage (S3, a second droplet) — a local-only backup doesn't survive the server it's backing up.
Limit login attempts
Rate-limit or lock out repeated failed logins at the application or reverse-proxy level — wp-login.php is the single most-attacked URL on any public WordPress install.
Quick Tips
upload_max_filesize/post_max_size in PHP, not a WordPress setting.Check phpinfo(), not just Settings → Media.Theme Directory Structure
/wp-content/themes/your-theme/
Every theme is its own folder here — the folder name is the theme's slug used throughout WordPress.
style.css
Required. A comment header block (Theme Name, Author, Version...) is what makes WordPress recognize the folder as a theme at all — the rest of the file is optional CSS.
functions.php
Auto-loaded on every request. Registers theme supports, enqueues assets, defines widget areas and nav menus — the theme's bootstrap file.
index.php
Required. The universal fallback template — if no more specific template matches, this is what renders.
screenshot.png
1200×900 preview shown in Appearance → Themes — optional but expected for any theme meant to be selected visually.
template-parts/
Convention (not required) for reusable chunks pulled in via get_template_part() — content cards, loop items, header/footer variants.
Template File Conventions
Classic (PHP) Theme
Block Theme (FSE)
Template Parts
Child Theme
Create the folder and style.css header
The comment block at the top of style.css is the only truly required file content — WordPress parses it to list the theme in Appearance → Themes.
Register theme supports in functions.php
Opt into core features — add_theme_support('title-tag'), 'post-thumbnails', 'html5' — rather than hand-coding what core already provides.
Build index.php as the fallback
Start with the one template every theme must have, using The Loop (have_posts() / the_post()) to output content.
Split out header, footer, sidebar
Move shared chrome into header.php/footer.php/sidebar.php, pulled in via get_header()/get_footer()/get_sidebar() — see the Theme Builder tab for the full pattern.
Add more specific templates as needed
Layer in single.php, page.php, archive.php etc. only where the fallback isn't enough — WordPress's template hierarchy picks the most specific match automatically.
Theming Tips
wp_enqueue_style()/wp_enqueue_script() hooked to wp_enqueue_scripts — hand-written <link>/<script> tags skip WordPress's dependency management and cache-busting.esc_html(), esc_attr(), esc_url() around any dynamic value printed in a template — the most common real-world theme security bug is skipping this.Setting Up a New Theme
Create the theme folder
Under /wp-content/themes/ — the folder name becomes the theme's slug everywhere in WordPress.
Add the style.css header block
This comment block is what WordPress actually parses to register the theme — everything below it is normal CSS (or nothing at all, if styles are enqueued separately).
Declare theme support in functions.php
Each add_theme_support() call opts into a core feature rather than reimplementing it.
Classic theme vs. Block theme (FSE)
A classic theme uses PHP template files and the template hierarchy below. A block theme replaces most PHP templates with HTML files under /templates/ and a root theme.json — see the last sub-tab for its config shape.
The Template Hierarchy
For any given request, WordPress walks a fixed priority order and renders the first matching file it finds in the theme — everything eventually falls back to index.php.
| Priority | Template File | Used For |
|---|---|---|
| 1 | front-page.php | The site's homepage, when a static front page is set — takes priority over home.php. |
| 2 | home.php | The main blog listing page (whether that's the homepage or a separate "Posts page"). |
| 3 | single.php | A single post. single-{post-type}.php (e.g. single-product.php) overrides it for a specific custom post type. |
| 4 | page.php | A static Page. page-{slug}.php or a Page Template assigned in the editor overrides it. |
| 5 | archive.php | Post type/date/author archives. category.php, tag.php, taxonomy.php take priority for their own contexts. |
| 6 | search.php | Search results listing. |
| 7 | 404.php | No matching content — always worth a real, styled 404.php rather than the fallback. |
| Last | index.php | The universal fallback — the only template file WordPress actually requires a theme to have. |
Enqueueing Assets Correctly
Common Theme Hooks
| Hook | Type | Fires |
|---|---|---|
after_setup_theme | Action | Early — the right place for add_theme_support() and register_nav_menus() calls. |
widgets_init | Action | When widget areas should be registered via register_sidebar(). |
wp_enqueue_scripts | Action | Front-end asset registration — wp_enqueue_style()/wp_enqueue_script() belong here. |
the_content | Filter | Transforms post content before output — where plugins like shortcode processors and embeds hook in. |
body_class | Filter | Adds/removes classes from the array passed to body_class() in the template. |
template_redirect | Action | Just before WordPress decides which template file to load — useful for custom redirects/overrides. |
theme.json (Block Themes / FSE)
A block theme replaces most PHP templates with HTML files under /templates/ and /parts/, configured centrally by a root theme.json instead of scattered add_theme_support() calls.