WP Code Generator — Tips & Tricks
Strategy and gotchas for the WP Code Generator: checking the output, shared fields, readme.txt rules, 7.x snippets, and useful combinations.
Back to the overview: WP Code Generator · Open the tool live: www.jpkc.com/tools/wp/
The manual describes every generator, the examples show the workflows. This page is about what both assume but rarely state: what the generated code does and doesn't do for you, where you should look more closely, and how to fit the tool sensibly into your workflow.
Scaffold, not a finished function
The most important point first: the WP Code Generator delivers boilerplate, not a solution. It takes the same error-prone typing off your hands every time — the plugin header, the register_post_type() signature, the Settings API cascade, the permission checks of a REST route —, but the actual logic lives in the function bodies you fill in yourself.
- Read the code before you adopt it. The new generators in particular comment in detail why something is built the way it is: why a number sanitizer is a helper of its own, why a taxonomy's default term stays untranslated, why a password field may stay empty. The tool doubles as a cheat sheet.
- Take the warnings seriously. The yellow list above the output doesn't just flag typos but real pitfalls — that
wp_insert_post()rejects a post without title, content, and excerpt, for example, or that a meta key starting with an underscore can't be bound to a block through the core sourcecore/post-meta. - Watch for substitute values. Not every generator checks every field. Where it doesn't, it quietly uses a default for empty fields — in Nav Menus, for instance, only the
primarylocation is created without an entry of your own, even though the form shows two rows with placeholder text. So check the output for everything you expect. - The tool doesn't know your installation. It doesn't know whether a hook exists, a slug is taken, or a capability is assigned to your roles. In the Custom Post Type, Taxonomy, and Post Status generators, it mentions some hard WordPress limits only in the info text: post type slugs may be at most 20 characters long, taxonomy slugs at most 32, and a custom post status must not share its name with a core status.
WordPress 7.x, PHP 8.3, and coding standards
The generated code targets WordPress 7.0 as the minimum and PHP 8.3. A few things to keep in mind:
- Set
Requires PHPhonestly. The code uses modern syntax such as typed signatures,mixed, the nullsafe operator?->, and in the plugin generator a typed class constant (public const string VERSION), which only exists from PHP 8.3. If you lower Requires PHP in the plugin generator, it drops the constant's type — the rest of the code isn't adapted. If you have to serve older servers, check the syntax yourself. - Don't cut the
ABSPATHguard. The linedefined( 'ABSPATH' ) || exit;prevents a PHP file from being called directly through its URL. Where the tool leaves it out, there's a reason:uninstall.phpchecksWP_UNINSTALL_PLUGIN, WP-CLI files checkWP_CLI. - Text domain equals folder name. In Plugin, Theme, and Block Bindings, the text domain follows the slug. If you overwrite it, the tool warns — wordpress.org requires them to match, because it keys language packs by the slug. Thanks to
Domain Pathin the header, you no longer needload_plugin_textdomain(). - Versions without upkeep. For your own CSS and JS files, the
filemtime()version strategy in the Asset Enqueue generator is a good choice: the browser reloads a changed file automatically. If you build with@wordpress/scripts, usebuild/*.asset.phpinstead — then version and dependencies are right. - Use newer options deliberately. Some theme and block options only exist in WordPress 7.1 (custom breakpoints or responsive styles, for example). The tool marks them and warns when they're newer than your minimum version — WordPress 7.0 would silently ignore them.
Use the shared fields deliberately
Copying author, text domain, and prefix live saves a lot of typing if you use it on purpose:
- Start with the plugin. Enter author and author URI in the Plugin generator first. The author lands in Theme and Block Bindings right away, the author URI in Theme. A text domain or prefix you type yourself spreads the same way to the other plugin-style generators — except Plugin and Block Bindings, whose text domain always follows their slug. Values the tool only derived are not copied.
- Theme and plugin are separate. The theme generators and the Text Domain / Prefix field of the snippets share a text domain of their own. That way you can build a plugin and a theme side by side without their values overwriting each other.
- Values you typed are safe. The copying only fills fields you haven't touched in the target generator. For a special case in a single generator, just enter it there.
- Clean up on shared computers. The tool remembers the values in the browser. If you work on a shared computer, click Forget saved defaults at the end — or use a private window from the start.
readme.txt and wordpress.org
If you want to publish a plugin in the wordpress.org directory, treat the plugin generator's warnings as a checklist:
- At most five tags, and
pluginandwordpressdon't count — the directory ignores both, and everything after the fifth tag as well. - The short description below the header has at most 150 characters and no markup. The tool takes it from the Description and trims it like the wordpress.org parser does.
- Stable tag is never
trunk. In the tool it follows the version; if the two differ, it warns. - Tested up to and Stable tag don't belong in the plugin header, but in
readme.txt— exactly how the tool splits them. - GPL-compatible only. If you pick Proprietary, the tool points out that wordpress.org only accepts GPL-compatible plugins.
Use snippets deliberately
The snippet library is convenient, but not a no-brainer:
- Must-use plugin rather than
functions.php. The default format is a separate file forwp-content/mu-plugins/. It loads automatically, without activation, and is already active before the regular plugins load. Thefunctions.phpvariant only loads after all plugins — too late for settings that plugins read while loading. - Set a prefix, avoid collisions. The Text Domain / Prefix field gives the snippets' functions a prefix of your own. When you combine several snippets or work alongside third-party code, that prevents duplicate function names.
- Check the options, don't copy blindly. 24 snippets have an options panel. Disable Comments, for example, can keep the comment REST endpoints for logged-in users — the Notes feature in the block editor needs them. Add Security Headers only sends
Strict-Transport-Securitywhen you tick it explicitly. - Understand what gets switched off. Disable XML-RPC cuts off services that still talk over XML-RPC. Disable Public REST API and Hide Users REST Endpoint can break plugins that use the REST API without logging in. Only use such snippets when you know the dependencies.
- Manage alt text centrally, but on purpose. Gutenberg Image Alt Text makes Image blocks output the alt text from the media library, replacing the one saved in the block. That pays off when your editors maintain alt text in the media library — but an alt text tailored to its context in a single block is no longer output (it stays saved, and it comes back once you remove the snippet). Images without a media library reference, such as ones inserted by URL, are left alone. If the media library entry is empty or contains only whitespace, the block's value stays.
- Security headers belong on the server. The Add Security Headers snippet sets headers through PHP, and only for the front end. Where you have access to the server configuration, they're usually better placed there — the snippet is the portable fallback.
- Know the 7.x switches. The WordPress 7.x & Editor group bundles what clients often ask for: turn off AI features, turn off Notes, turn off the Font Library (optionally including the Google Fonts collection), run the editor without content from wordpress.org, or take abilities out of the REST API. For AI there's also the
WP_AI_SUPPORTconstant in the WP-Config generator.
Combine the right generators
Many tasks need several generators in a row. Typical chains:
- Plugin + data types + Block Bindings. First the Plugin, then Custom Post Type (with
show_in_restandcustom-fields) and Taxonomy, then the fields — either as a Post Meta Field with the Block Bindings switch, which makes the field bindable to core blocks, or straight away as your own source with the Block Bindings generator. - Block theme + patterns + styles. The Theme generator already ships a pattern and style variations. You get more patterns from Block Patterns in Theme mode, custom styles for core blocks from Block Styles, and variations from Block Variations.
- Open content to AI and automations. An Abilities API ability describes what an agent may do, including schemas and permissions. If you need a classic endpoint for your own applications, use REST Route. If you want to talk to an AI model yourself, AI Prompt provides the function.
- Settings + notice. A Settings Page for the API key, plus an Admin Notice on the settings page — the preset "API key missing." fits. You do have to adjust the notice's Screen ID to the settings page, though:
toplevel_page_<menu-slug>for the default top-level page,settings_page_<menu-slug>for a submenu under Settings (options-general.php).<menu-slug>is the Settings Page's Menu Slug (defaultmy-plugin-settings), not the text domain the Admin Notice generator derives its pre-filledsettings_page_my-pluginfrom. You add the check whether the key is missing to the function yourself. - Dashicons as a supplier. Whenever a generator wants an icon — custom post type, block, block variation —, the Dashicons browser delivers the name with one click, optionally already in the format for
block.json.
Combine with other JPKCom tools
The WP Code Generator produces the scaffold — these tools round out the workflow:
- Beautify — formats JavaScript, CSS, and HTML. When you want to re-indent a generated block's JS or the theme CSS after your own edits, this is the place. (Note: Beautify covers JS/CSS/HTML, not PHP.)
- Source Viewer — view source code in 100+ languages with syntax highlighting; good for reading, checking, or sharing a generated snippet.
- SEO & GEO Analyzer — once the plugin or theme is live, audit the delivered page here for SEO, AI readiness, and technical health. That closes the loop from code to a finished, optimized site.
More context: the overview for the big picture, the manual for every generator, and the examples for the step-by-step workflows. You can try everything directly in the tool.