WP Code Generator — Examples
Concrete runs with the WP Code Generator: a plugin header, a custom hook, a Gutenberg block, a theme snippet, and more — step by step.
Back to the overview: WP Code Generator · Open the tool live: www.jpkc.com/tools/wp/
The manual describes every generator and its fields. This page adds concrete workflows: typical tasks played through step by step, with a focus on which fields produce which code and what you do with it afterwards. The tool's interface is in English, so the generator and field names appear in their original spelling.
Example 1: Generate a plugin header
You're starting a new plugin and need the correct header plus a main class.
- Open the WP Code Generator — the Plugin generator is active by default.
- Type something like
My Awesome Plugininto Plugin Name. Watch Text Domain turn intomy-awesome-pluginand Namespace / Main Class intoMyAwesomePluginautomatically. You can override both. - Add Author, Plugin URI, and a Description. Leave Requires WP at
6.8and Requires PHP at8.3, pick a License (e.g. GPL-2.0-or-later). For a multisite-only plugin, enable Network. - The code updates live in the
plugin.phpeditor. It contains the full doc header,declare(strict_types=1), and adefined('ABSPATH') || exitguard — roughly like this:
<?php
/**
* Plugin Name: My Awesome Plugin
* Description: A custom WordPress plugin.
* Version: 1.0.0
* Author: John Doe
* License: GPL-2.0-or-later
* Text Domain: my-awesome-plugin
* Requires at least: 6.8
* Requires PHP: 8.3
*/
declare( strict_types=1 );
defined( 'ABSPATH' ) || exit;- Click Download to save the file as
plugin.php, or Copy and paste it into your project. The text domain must match the plugin directory name.
Example 2: Create a filter hook
You want to modify the post excerpt programmatically and need the correct hook scaffold.
- In the sidebar, under Hooks & Assets, choose the Hook (Action / Filter) generator.
- Set Type to Filter (add_filter) — because a filter modifies and returns a value, unlike an action.
- Type
the_contentinto Hook Name (the field suggests common hooks). Set Priority to10, Accepted Args to1, and Callback Function Name tomy_filter_content. - The editor shows a scaffold like this:
add_filter( 'the_content', 'my_filter_content', 10, 1 );
function my_filter_content( $content ) {
// Modify $content here.
return $content;
}- Mind the difference from an action: a filter function must return the (modified) value, otherwise the content disappears. Accepted Args must match the number of parameters the hook actually passes.
Example 3: Register a dynamic Gutenberg block
You're building a block whose output should be rendered server-side (e.g. a list of recent posts).
- Under Plugin & Theme, choose the Gutenberg Block generator.
- Enter Namespace (your plugin slug, e.g.
my-plugin), Block Name (latest-posts), Title, and a Description. Pick a Category (e.g.widgets) and an Icon Dashicon. - Enable Dynamic Block (server-side render). The Render Callback Function Name field now appears — enter e.g.
my_plugin_render_latest_posts. - The
block.jsontab holds the block definition (with the"render"/ callback wiring), theregister.phptab the PHP registration viaregister_block_type(). For dynamic blocks the JSsave()function returnsnulland the PHP callback produces the markup. - Copy/Download always refer to the active file tab — so grab both files individually (
block.jsonandregister.php).
Example 4: Generate a custom post type
You need a custom content type called "Projects".
- Under Data Types, choose the Custom Post Type generator.
- Enter the slug (
project) and the labels (singular/plural), pick the Supports (title, editor, thumbnail …), the REST integration (for the block editor and the REST API), and a menu_icon — find the Dashicon slug via the Dashicons browser under Reference. - The editor shows a complete
register_post_type()call with a filled-out labels array, hooked to theinitaction. Copy it into your plugin or your theme'sfunctions.php. - If you also need a taxonomy ("Project Categories"), switch to the Taxonomy generator next and associate it with the
projectpost type.
Example 5: Grab a ready-made theme snippet
You want a quick, safe optimization in your functions.php without writing it yourself.
- Under Snippets, choose the Theme Snippets tab.
- Open the Snippet dropdown and, in the Security & Cleanup category, pick Remove Generator Meta Tag. A short description appears below it explaining why the snippet is useful.
- The editor immediately shows the finished code:
<?php
/**
* Remove the WordPress generator meta tag.
*/
remove_action( 'wp_head', 'wp_generator' );- If you need a custom function prefix (e.g. to avoid name collisions), enter it in the Text Domain / Prefix field — the code is then regenerated with prefixed function names. Some snippets (e.g. Remove Emoji Support) additionally reveal a small options panel.
- Copy or Download (as
remove-generator.php) — and intofunctions.phpit goes.
Example 6: Click together a database query
You need a WP_Query that sorts by a meta field.
- Under Config & Queries, choose the Query Builder.
- Leave Query Type at WP_Query (posts). The form shows the matching fields.
- Set Post Type (
product), Post Status (publish), Posts per Page (12), and Order By tometa_value_num. - The editor builds the full
WP_Querycall including the arguments array and the correct loop (have_posts()/the_post()/wp_reset_postdata()). If you need users, terms, or comments instead, switch Query Type toget_users(),get_terms(), orget_comments()— the form adapts, and an info box explains the chosen type.
There's more depth in the manual for every generator and field, and in the tips & tricks for strategy and gotchas. You can try everything directly in the tool.