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

Source: https://www.jpkc.com/db/en/tools/wp/examples/

Back to the overview: [WP Code Generator](https://www.jpkc.com/db/en/tools/wp/) · Open the tool live: [www.jpkc.com/tools/wp/](https://www.jpkc.com/tools/wp/)

The [manual](https://www.jpkc.com/db/en/tools/wp/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.

1. Open the [WP Code Generator](https://www.jpkc.com/tools/wp/) — the **Plugin** generator is active by default.
2. Type something like `My Awesome Plugin` into *Plugin Name*. Watch *Text Domain* turn into `my-awesome-plugin` and *Namespace / Main Class* into `MyAwesomePlugin` automatically. You can override both.
3. Add *Author*, *Plugin URI*, and a *Description*. Leave *Requires WP* at `6.8` and *Requires PHP* at `8.3`, pick a *License* (e.g. GPL-2.0-or-later). For a multisite-only plugin, enable *Network*.
4. The code updates live in the `plugin.php` editor. It contains the full doc header, `declare(strict_types=1)`, and a `defined('ABSPATH') || exit` guard — roughly like this:

```php
<?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;
```

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

1. In the sidebar, under *Hooks & Assets*, choose the **Hook (Action / Filter)** generator.
2. Set *Type* to **Filter (add_filter)** — because a filter modifies and **returns a value**, unlike an action.
3. Type `the_content` into *Hook Name* (the field suggests common hooks). Set *Priority* to `10`, *Accepted Args* to `1`, and *Callback Function Name* to `my_filter_content`.
4. The editor shows a scaffold like this:

```php
add_filter( 'the_content', 'my_filter_content', 10, 1 );

function my_filter_content( $content ) {

	// Modify $content here.

	return $content;
}
```

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

1. Under *Plugin & Theme*, choose the **Gutenberg Block** generator.
2. 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.
3. Enable **Dynamic Block (server-side render)**. The *Render Callback Function Name* field now appears — enter e.g. `my_plugin_render_latest_posts`.
4. The `block.json` tab holds the block definition (with the `"render"` / callback wiring), the `register.php` tab the PHP registration via `register_block_type()`. For dynamic blocks the JS `save()` function returns `null` and the PHP callback produces the markup.
5. **Copy/Download** always refer to the active file tab — so grab both files individually (`block.json` and `register.php`).

## Example 4: Generate a custom post type

You need a custom content type called "Projects".

1. Under *Data Types*, choose the **Custom Post Type** generator.
2. 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*.
3. The editor shows a complete `register_post_type()` call with a filled-out labels array, hooked to the `init` action. Copy it into your plugin or your theme's `functions.php`.
4. If you also need a taxonomy ("Project Categories"), switch to the **Taxonomy** generator next and associate it with the `project` post type.

## Example 5: Grab a ready-made theme snippet

You want a quick, safe optimization in your `functions.php` without writing it yourself.

1. Under *Snippets*, choose the **Theme Snippets** tab.
2. 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.
3. The editor immediately shows the finished code:

```php
<?php
/**
 * Remove the WordPress generator meta tag.
 */
remove_action( 'wp_head', 'wp_generator' );
```

4. 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.
5. **Copy** or **Download** (as `remove-generator.php`) — and into `functions.php` it goes.

## Example 6: Click together a database query

You need a `WP_Query` that sorts by a meta field.

1. Under *Config & Queries*, choose the **Query Builder**.
2. Leave *Query Type* at **WP_Query (posts)**. The form shows the matching fields.
3. Set *Post Type* (`product`), *Post Status* (`publish`), *Posts per Page* (`12`), and *Order By* to `meta_value_num`.
4. The editor builds the full `WP_Query` call 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* to `get_users()`, `get_terms()`, or `get_comments()` — the form adapts, and an info box explains the chosen type.

---

There's more depth in the [manual](https://www.jpkc.com/db/en/tools/wp/manual/) for every generator and field, and in the [tips & tricks](https://www.jpkc.com/db/en/tools/wp/tips/) for strategy and gotchas. You can try everything directly in the [tool](https://www.jpkc.com/tools/wp/).

