Back to All Cheatsheet Libraries cheatsheets

WordPress

WP-CLI commands, key hooks and wp-config constants, and a baseline hardening checklist for admins running WordPress in production.

Total Commands: 0
Category Command Description
Corewp core downloadDownloads WordPress core files into the current directory.
Corewp core install --url=<url> --title=<title> --admin_user=<user> --admin_password=<pass> --admin_email=<email>Runs the famous 5-minute install non-interactively.
Corewp core updateUpdates WordPress core to the latest version.
Corewp core versionPrints the current WordPress version.
Pluginswp plugin listLists installed plugins with status, version, and update availability.
Pluginswp plugin install <slug> --activateInstalls a plugin from the WordPress.org repo and activates it.
Pluginswp plugin update --allUpdates every plugin with an available update.
Pluginswp plugin deactivate --allDeactivates every active plugin at once — the fastest way to isolate a white-screen error.
Themeswp theme listLists installed themes and which one is active.
Themeswp theme activate <slug>Switches the active theme.
Databasewp db export backup.sqlExports the database to a SQL file.
Databasewp db import backup.sqlImports a SQL file into the site's database.
Databasewp search-replace 'old.com' 'new.com'Safely rewrites a domain/URL across all tables, including serialized PHP data.
Databasewp db optimizeRuns OPTIMIZE TABLE across the database to reclaim space and defragment.
Userswp user list --role=administratorLists all users with the administrator role.
Userswp user update <id> --user_pass=<newpass>Resets a user's password directly — the standard "locked out of wp-admin" fix.
Userswp user create <login> <email> --role=administratorCreates a new admin user from the command line.
Maintenancewp cache flushFlushes the object cache (works with Redis/Memcached backends too).
Maintenancewp rewrite flushRegenerates permalink rewrite rules — fixes most 404-on-post-URL issues.
Maintenancewp transient delete --allClears every transient — useful when cached data has gone stale or corrupt.
Maintenancewp cron event run --allManually fires every due WP-Cron event — useful for debugging scheduled tasks.
Securitywp config set WP_DEBUG true --rawToggles debug mode in wp-config.php from the CLI.
Securitywp option get siteurlReads 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

init after_setup_theme widgets_init wp_enqueue_scripts

Content

the_content save_post pre_get_posts the_title

Auth & Users

wp_login wp_logout user_register authenticate

REST & Admin

rest_api_init admin_menu admin_init admin_notices

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.

Baseline Hardening Checklist

The handful of steps that matter most for a WordPress site an admin is actually responsible for keeping online.

1

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.

2

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.

3

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.

4

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.

5

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

Object cache first
A persistent object cache (Redis/Memcached) fixes more WordPress performance complaints than any plugin — page caching alone still hits the database on every uncached request.
uploads.ini for large media
If media uploads fail silently, it's almost always upload_max_filesize/post_max_size in PHP, not a WordPress setting.Check phpinfo(), not just Settings → Media.
Staging before major updates
Clone to a staging copy before a major core/PHP version bump — plugin compatibility breaks are the #1 cause of a bad-update emergency call.

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

index.php + template hierarchyThe Loop

Block Theme (FSE)

theme.json + HTML templatesNo PHP required

Template Parts

get_template_part()Reusable component chunks

Child Theme

style.css Template: headerSafely overrides a parent

Building a Custom Theme, Start to Finish

The practical build order for a classic PHP theme — see the Theme Builder tab for the deeper, comprehensive version of each step.

1

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.

/* Theme Name: My Theme Author: Your Name Version: 1.0 */
2

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.

3

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.

4

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.

5

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

Never edit a theme you didn't build
Direct edits to a downloaded/purchased theme vanish on its next update — create a child theme instead, or a separate custom theme if going further than minor tweaks.
Enqueue, never hardcode, assets
CSS/JS belongs in wp_enqueue_style()/wp_enqueue_script() hooked to wp_enqueue_scripts — hand-written <link>/<script> tags skip WordPress's dependency management and cache-busting.
Escape everything you output
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.

Comprehensive WordPress Theme Builder

The one-stop reference for classic PHP theme development — main page structure, sidebar/template parts, header/footer/menus, and the hooks + theme.json options every theme leans on.

Setting Up a New Theme

1

Create the theme folder

Under /wp-content/themes/ — the folder name becomes the theme's slug everywhere in WordPress.

2

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).

/* Theme Name: My Custom Theme Theme URI: https://example.com Author: Your Name Description: A custom theme. Version: 1.0 Text Domain: my-theme */
3

Declare theme support in functions.php

Each add_theme_support() call opts into a core feature rather than reimplementing it.

function my_theme_setup() { add_theme_support( 'title-tag' ); add_theme_support( 'post-thumbnails' ); add_theme_support( 'html5', array( 'search-form', 'comment-form' ) ); add_theme_support( 'custom-logo' ); } add_action( 'after_setup_theme', 'my_theme_setup' );
4

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
1front-page.phpThe site's homepage, when a static front page is set — takes priority over home.php.
2home.phpThe main blog listing page (whether that's the homepage or a separate "Posts page").
3single.phpA single post. single-{post-type}.php (e.g. single-product.php) overrides it for a specific custom post type.
4page.phpA static Page. page-{slug}.php or a Page Template assigned in the editor overrides it.
5archive.phpPost type/date/author archives. category.php, tag.php, taxonomy.php take priority for their own contexts.
6search.phpSearch results listing.
7404.phpNo matching content — always worth a real, styled 404.php rather than the fallback.
Lastindex.phpThe universal fallback — the only template file WordPress actually requires a theme to have.

A minimal index.php using The Loop

Every classic template that lists or shows post content runs this same pattern.

<?php get_header(); ?> <main id="main-content"> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> </article> <?php endwhile; ?> <?php the_posts_pagination(); ?> <?php else : ?> <p><?php esc_html_e( 'No content found.', 'my-theme' ); ?></p> <?php endif; ?> </main> <?php get_sidebar(); get_footer(); ?>

Enqueueing Assets Correctly

functions.php

Always hook to wp_enqueue_scripts — never print <link>/<script> tags by hand in a template.

function my_theme_assets() { wp_enqueue_style( 'my-theme-style', get_stylesheet_uri(), array(), '1.0' ); wp_enqueue_script( 'my-theme-main', get_template_directory_uri() . '/js/main.js', array(), '1.0', true ); } add_action( 'wp_enqueue_scripts', 'my_theme_assets' );

Common Theme Hooks

Hook Type Fires
after_setup_theme ActionEarly — the right place for add_theme_support() and register_nav_menus() calls.
widgets_init ActionWhen widget areas should be registered via register_sidebar().
wp_enqueue_scripts ActionFront-end asset registration — wp_enqueue_style()/wp_enqueue_script() belong here.
the_content FilterTransforms post content before output — where plugins like shortcode processors and embeds hook in.
body_class FilterAdds/removes classes from the array passed to body_class() in the template.
template_redirect ActionJust 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.

A minimal theme.json

Defines the color/typography settings the block editor exposes to users, plus global styles.

{ "$schema": "https://schemas.wp.org/trunk/theme.json", "version": 2, "settings": { "color": { "palette": [ { "slug": "primary", "color": "#1e293b", "name": "Primary" } ] }, "typography": { "fontSizes": [ { "slug": "medium", "size": "1rem", "name": "Medium" } ] } }, "styles": { "color": { "background": "#ffffff", "text": "#1e293b" } } }
Classic and block themes can mix
A "hybrid" theme keeps PHP templates but adds a theme.json for editor styling controls — full FSE isn't all-or-nothing.
templates/index.html is the FSE fallback
In a block theme, /templates/index.html plays the same universal-fallback role that index.php plays in a classic theme.