Hardening a WordPress theme and server layer against common automated probes reduces attack exposure without adding database queries or heavy security plugins. The CodeToWP WordPress Theme Security Hardening Generator gives WordPress developers, agencies, and freelancers modular PHP filters, Apache .htaccess rules, and wp-config.php constants tailored to their chosen hardening profile.
Who the WordPress Theme Security Hardening Generator Is Built For
Default WordPress installs leave several reconnaissance and legacy endpoints active, including HTML generator tags, asset ?ver= disclosure strings, unauthenticated /wp-json/wp/v2/users enumeration, XML-RPC pingbacks, and the built-in admin theme file editor. Installing bloated all-in-one firewall plugins often slows down admin and frontend response times with unnecessary background logging.
Instead, the WordPress Theme Security Hardening Generator lets you toggle 10 targeted hardening rules aligned with the WordPress Developer Security Handbook and export clean code directly without plugin bloat.
Features, Settings & Supported Outputs
- 3 Security Profile Presets & 10 Toggles: Switch among Essential Production (enables 7 core checks = 70% Moderate), Strict Enterprise Lockdown (all 10 checks = 100% Hardened), and E-Commerce Profile (9 checks = 90% Hardened, leaving REST user endpoints enabled for compatibility) or customize all 10 toggles individually alongside a live percentage score meter.
- Tab 1 —
inc/security.php(Downloads asinc-security.php): Outputs optional hooks forsend_headerssecurity headers (X-Content-Type-Options,X-Frame-Options: SAMEORIGIN,Referrer-Policy,Permissions-Policy),wp_generatorremoval,?ver=query stripping, XML-RPC & pingback disable, logged-out REST/wp/v2/usersblocking, author archive redirect, and genericlogin_errorsmessages. - Tab 2 —
.htaccessRules: EmitsOptions -Indexes, sensitive file protection (wp-config.php,.env, logs, backups via Apache 2.4+Require all denied),xmlrpc.phpaccess blocks,?author=Nrewrite blocks, andmod_headersresponse headers. - Tab 3 —
wp-config.phpConstants (Downloads aswp-config-snippet.php): Conditionally outputsDISALLOW_FILE_EDITandWP_POST_REVISIONS(5) alongside baselineFORCE_SSL_ADMINandEMPTY_TRASH_DAYSconstants.
Practical Example: Blocking REST Enumeration & Adding HTTP Headers
Sample Toggle Selection
Toggles Active: HTTP Security Headers (ON), Block REST API User Enumeration (ON), Disable XML-RPC (ON)
Output Tab: inc/security.php
Expected Generated PHP Excerpt
function codetowp_send_security_headers() {
if ( ! is_admin() ) {
header( 'X-Content-Type-Options: nosniff' );
header( 'X-Frame-Options: SAMEORIGIN' );
header( 'Referrer-Policy: strict-origin-when-cross-origin' );
header( 'Permissions-Policy: geolocation=(), microphone=(), camera=()' );
}
}
add_action( 'send_headers', 'codetowp_send_security_headers' );
add_filter( 'rest_endpoints', function( $endpoints ) {
if ( ! is_user_logged_in() ) {
unset( $endpoints['/wp/v2/users'], $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
}
return $endpoints;
} );
Result Explanation: Anonymous requests to /wp-json/wp/v2/users receive a 404/empty route without blocking logged-in Gutenberg/Admin API calls, while frontend responses carry protective framing and MIME headers.
Practical Use Cases
- WordPress Theme Developers: Drop a uniform
inc/security.phpbaseline module into every custom client build. - Agencies: Enforce HTTP response headers and disable theme/plugin file editing across managed client installations.
- WooCommerce & E-Commerce Builders: Use the E-Commerce preset to lock down headers, XML-RPC, and config files without breaking authenticated REST requests.
- Freelancers: Harden brochure and portfolio sites cleanly at the PHP and Apache config layers instead of relying on heavy security suites.
Limitations & Compatibility
- Author Enumeration Filter vs. Multi-Author Blogs: In
inc/security.php, enabling Prevent Username Scanning usesis_author()to redirect all frontend author archive pages to the homepage. On multi-author blogs that want public author archive URLs, leave that PHP toggle off and rely on the.htaccessquery-string rule (author=([0-9]+)) instead. - Apache 2.4+ Syntax in
.htaccess: The.htaccesstab uses Apache 2.4 directives (Require all denied,RewriteEngine On). Nginx, OpenLiteSpeed/Caddy configurations, or Apache 2.2 servers require adapting rules to their native syntax, and server/config edits should always be verified on staging first. wp-config.phpConstants & REST Coverage: Notice thewp-config.phptab emitsdefine( 'AUTOMATIC_UPDATER_DISABLED', false );(which keeps background updates enabled; switch totrueonly if managing updates externally via CI/CD). Also, disabling XML-RPC and blocking/wp/v2/usersvia PHP works best alongside blockingxmlrpc.phpat the server level, and does not strip author names from oEmbed endpoints.- Compatibility: PHP snippets work cleanly across WordPress 5.5–6.7+ and PHP 8.0–8.3+.
Next Steps & Related CodeToWP Tools
Pair output from this WordPress Theme Security Hardening Generator with sanitized vectors from our Sanitized SVG Icon Cleaner, generate a starter theme with inc/security.php support in the Starter Theme ZIP Generator, and follow our full WordPress Theme Security Hardening Checklist.