HZ Post Enhancer: Subtitle + Featured Meta Box

⏲️ Estimated reading time: 13 min

Learn how to add a secure, production-ready WordPress meta box for post subtitles and a Featured toggle, then display them beautifully on the frontend (GeneratePress-friendly). Includes best-practice saving logic, clean CSS, featured queries, and optional upgrades for admin columns, shortcodes, and SEO workflows.


Why You’d Want a Subtitle + Featured Toggle in WordPress

A subtitle gives your post a second line that can explain the topic in a human way. It also helps readers scan faster, especially on archive pages.

A “Featured” checkbox is a simple editorial tool. You can mark the best posts, then build sections like “Top Picks” or “Editor’s Choice” without sticky hacks.

Together, they give you a clean content workflow. You write better posts. You organize faster. You highlight what matters.


What We’re Building Today

We’ll build a secure, production-ready solution that adds:

A Sidebar Meta Box in the Post Editor

The meta box includes a subtitle input and a Featured checkbox.

Safe Saving Logic (Production-Ready)

We’ll protect saving with nonce checks, capability checks, autosave protection, and revision checks.

Frontend Display for GeneratePress

We’ll output the subtitle under the post title (without breaking your theme).

A Simple Featured Query

We’ll show how to fetch only featured posts for homepage blocks and custom sections.


Before You Paste Anything

You have two safe ways to add this to your site.

Option A: Put It in Your Child Theme

This is quick, but theme switching will remove the feature.

Option B: Make It a Small Plugin

This is the best long-term method. Your feature stays active even if you change themes.

Because you asked for “production-ready plugin quality,” we’ll do the plugin approach first, then I’ll also show the child-theme method as a shortcut.


The Production-Ready Plugin Version

This version is clean, safe, and organized. It includes proper plugin headers, hooks, and best-practice checks.

Plugin Folder and File Path

Create this folder:

wp-content/plugins/hz-post-enhancer/

Inside it, create this file:

hz-post-enhancer.php


Full Plugin Code: HZ Post Enhancer

Copy-paste everything below into hz-post-enhancer.php.

<?php
/**
 * Plugin Name: HZ Post Enhancer (Subtitle + Featured)
 * Description: Adds a secure meta box for post subtitle and a Featured toggle, plus helper hooks for frontend display and featured queries.
 * Version: 1.0.0
 * Author: Tokyo Blade
 * License: GPLv2 or later
 * Text Domain: hz-post-enhancer
 */

if (!defined('ABSPATH')) {
    exit;
}

final class HZ_Post_Enhancer {

    const META_SUBTITLE = '_post_subtitle';
    const META_FEATURED = '_is_featured';
    const NONCE_ACTION  = 'hz_post_enhancer_nonce_action';
    const NONCE_NAME    = 'hz_post_enhancer_nonce';

    public static function init(): void {
        add_action('add_meta_boxes', [__CLASS__, 'register_meta_box']);
        add_action('save_post_post', [__CLASS__, 'save_meta'], 10, 2);
    }

    public static function register_meta_box(): void {
        add_meta_box(
            'hz_post_enhancer_box',
            __('Additional Post Information', 'hz-post-enhancer'),
            [__CLASS__, 'render_meta_box'],
            'post',
            'side',
            'default'
        );
    }

    public static function render_meta_box(\WP_Post $post): void {
        wp_nonce_field(self::NONCE_ACTION, self::NONCE_NAME);

        $subtitle = get_post_meta($post->ID, self::META_SUBTITLE, true);
        $featured = get_post_meta($post->ID, self::META_FEATURED, true);

        ?>
        <p>
            <label for="hz_post_subtitle"><strong><?php esc_html_e('Subtitle:', 'hz-post-enhancer'); ?></strong></label>
            <input
                type="text"
                id="hz_post_subtitle"
                name="hz_post_subtitle"
                value="<?php echo esc_attr((string) $subtitle); ?>"
                class="widefat"
                placeholder="<?php esc_attr_e('Short supporting line under the title', 'hz-post-enhancer'); ?>"
            />
        </p>

        <p style="margin-top:10px;">
            <label>
                <input
                    type="checkbox"
                    name="hz_is_featured"
                    value="yes"
                    <?php checked($featured, 'yes'); ?>
                />
                <?php esc_html_e('Feature this post', 'hz-post-enhancer'); ?>
            </label>
        </p>
        <?php
    }

    public static function save_meta(int $post_id, \WP_Post $post): void {

        if (!isset($_POST[self::NONCE_NAME])) {
            return;
        }

        $nonce = (string) $_POST[self::NONCE_NAME];
        if (!wp_verify_nonce($nonce, self::NONCE_ACTION)) {
            return;
        }

        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return;
        }

        if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
            return;
        }

        if (!current_user_can('edit_post', $post_id)) {
            return;
        }

        if ($post->post_type !== 'post') {
            return;
        }

        if (isset($_POST['hz_post_subtitle'])) {
            $subtitle = sanitize_text_field(wp_unslash($_POST['hz_post_subtitle']));
            update_post_meta($post_id, self::META_SUBTITLE, $subtitle);
        }

        $featured = isset($_POST['hz_is_featured']) ? 'yes' : 'no';
        update_post_meta($post_id, self::META_FEATURED, $featured);
    }
}

HZ_Post_Enhancer::init();

What Each Important Part Does

You asked to “prezintă codul,” so here’s the human explanation simple and direct.

Plugin Header and Safety Gate

The header makes WordPress recognize it as a plugin. The ABSPATH check blocks direct access.

Class-Based Structure

A class keeps things clean and avoids function name conflicts. It also helps when you add more features later.

Constants for Meta Keys and Nonce

We store keys like _post_subtitle in constants so you don’t accidentally mistype them later.

add_meta_boxes Hook

This adds the meta box to the post editor.

save_post_post Hook

This runs only for posts (not pages). It’s tighter and safer than save_post.

Nonce + Capability Checks

Nonce proves the request came from your editor screen. Capability check ensures only allowed users save.

Autosave + Revision Protection

WordPress makes autosaves and revisions. We skip those so you don’t get weird meta duplication.

Sanitization and wp_unslash

WordPress adds slashes in POST sometimes. wp_unslash normalizes the input. sanitize_text_field keeps it clean.

Checkbox Fallback

If the checkbox is not sent, we store no. That keeps data consistent.


How to Enable the Plugin

Once you created the folder and file:

Activate It from WordPress Admin

Go to PluginsInstalled Plugins → Activate HZ Post Enhancer (Subtitle + Featured).

Confirm It Works in the Editor

Edit any post and look in the sidebar. You’ll see the meta box.


How to Display the Subtitle on the Frontend (GeneratePress)

Now we’ll print the subtitle under the post title.

Add This Snippet to GeneratePress Child Theme

Open:

wp-content/themes/generatepress_child/functions.php

Add this:

add_action('generate_after_entry_title', function () {

    if (!is_singular('post')) {
        return;
    }

    $subtitle = get_post_meta(get_the_ID(), '_post_subtitle', true);

    if (!empty($subtitle)) {
        echo '<p class="post-subtitle">' . esc_html($subtitle) . '</p>';
    }
});

Subtitle Styling That Looks Clean and Premium

Add this CSS to your child theme:

Where to Add the CSS

Go to AppearanceCustomizeAdditional CSS
Or put it in your child theme stylesheet.

CSS Code

.post-subtitle{
    font-size:18px;
    font-weight:400;
    color:#777;
    margin-top:-10px;
    margin-bottom:20px;
    line-height:1.4;
}

How to Show Only Featured Posts in a Custom Section

You can pull only featured posts using a meta query.

Featured Posts WP_Query Example

$args = [
    'post_type'      => 'post',
    'posts_per_page' => 8,
    'meta_key'       => '_is_featured',
    'meta_value'     => 'yes',
    'orderby'        => 'date',
    'order'          => 'DESC',
];

$featured_query = new WP_Query($args);

if ($featured_query->have_posts()) {
    while ($featured_query->have_posts()) {
        $featured_query->the_post();

        echo '<h3><a href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a></h3>';

        $subtitle = get_post_meta(get_the_ID(), '_post_subtitle', true);
        if ($subtitle) {
            echo '<p class="post-subtitle">' . esc_html($subtitle) . '</p>';
        }
    }
    wp_reset_postdata();
}

A Cleaner Way: Featured Posts Shortcode

If you want to drop featured posts inside any page, a shortcode is gold.

Add This Shortcode to the Plugin

Paste this below HZ_Post_Enhancer::init(); in the plugin file.

add_shortcode('hz_featured_posts', function ($atts) {

    $atts = shortcode_atts([
        'limit' => 6,
    ], $atts, 'hz_featured_posts');

    $limit = max(1, (int) $atts['limit']);

    $q = new WP_Query([
        'post_type'      => 'post',
        'posts_per_page' => $limit,
        'meta_key'       => '_is_featured',
        'meta_value'     => 'yes',
        'orderby'        => 'date',
        'order'          => 'DESC',
        'no_found_rows'  => true,
    ]);

    if (!$q->have_posts()) {
        return '';
    }

    ob_start();

    echo '<div class="hz-featured-posts">';
    while ($q->have_posts()) {
        $q->the_post();

        $subtitle = get_post_meta(get_the_ID(), '_post_subtitle', true);

        echo '<article class="hz-featured-item">';
        echo '<h3 class="hz-featured-title"><a href="' . esc_url(get_permalink()) . '">' . esc_html(get_the_title()) . '</a></h3>';

        if (!empty($subtitle)) {
            echo '<p class="hz-featured-subtitle">' . esc_html($subtitle) . '</p>';
        }

        echo '</article>';
    }
    echo '</div>';

    wp_reset_postdata();

    return ob_get_clean();
});

Shortcode CSS That Matches a Modern Blog

Add this CSS in Additional CSS:

.hz-featured-posts{
    display:block;
    margin:20px 0;
}
.hz-featured-item{
    padding:14px 0;
    border-bottom:1px solid rgba(0,0,0,.08);
}
.hz-featured-title{
    margin:0 0 6px 0;
    font-size:18px;
    line-height:1.3;
}
.hz-featured-subtitle{
    margin:0;
    color:#777;
    font-size:15px;
    line-height:1.45;
}

How to Use the Shortcode in WordPress

Open any page or post and add:

[hz_featured_posts limit="6"]

That’s it. You now have an “Editor’s Picks” block you can place anywhere.


Admin Quality Upgrade: Add a “Featured” Column in Posts List

This makes your editorial workflow faster. You’ll see featured posts instantly in the admin list.

Add This to the Plugin File

Paste below the class, near the bottom:

add_filter('manage_post_posts_columns', function ($columns) {
    $columns['hz_featured'] = __('Featured', 'hz-post-enhancer');
    return $columns;
});

add_action('manage_post_posts_custom_column', function ($column, $post_id) {
    if ($column !== 'hz_featured') {
        return;
    }

    $featured = get_post_meta($post_id, '_is_featured', true);
    echo ($featured === 'yes') ? '✅' : '-';
}, 10, 2);

add_filter('manage_edit-post_sortable_columns', function ($columns) {
    $columns['hz_featured'] = 'hz_featured';
    return $columns;
});

add_action('pre_get_posts', function ($query) {
    if (!is_admin() || !$query->is_main_query()) {
        return;
    }

    if ($query->get('orderby') === 'hz_featured') {
        $query->set('meta_key', '_is_featured');
        $query->set('orderby', 'meta_value');
    }
});

SEO Use Case: Subtitle as a Smart “Excerpt Backup

If you want, the subtitle can help when a post has a weak excerpt. It keeps the post preview clear.

A Simple Editorial Rule That Works

Write subtitles like a one-line promise. Keep it human. Avoid keyword stuffing.

Example Subtitle Style

A good subtitle explains what the reader gets, in one breath. It feels like a friendly hint, not a sales pitch.


Performance Notes for Big Sites

This setup is lightweight. It uses post meta and standard hooks.

Why It Stays Fast

Meta fields load only for the post you edit. Frontend display calls one get_post_meta, which is cheap.

When to Cache Featured Queries

If you show featured posts on every page load, cache the output with a transient or object cache. You already love performance tuning, so this is your “Tokyo Blade” zone.


Common Mistakes That Break Meta Boxes

This section saves you headaches.

Forgetting wp_unslash

WordPress may add slashes. Unsplash then sanitize.

Saving on Autosave

Autosave can overwrite or duplicate. We block it.

Missing Checkbox Fallback

Unchecked checkboxes don’t send POST values. Without fallback, you get inconsistent meta.

Using save_post Without Post Type Targeting

save_post_post is cleaner. It runs only for posts.

Subtitle + Featured Meta Box

Frequently Asked Questions

Can I use this for Pages too?

Yes. Change the meta box target from post to page (or register for both) and switch the save hook to save_post_page for pages.

Will this work with Gutenberg?

Yes. This is a classic meta box in the sidebar area of the editor screen. It works with Gutenberg because it’s still the post edit screen.

Is the code secure?

Yes. It uses nonce verification, capability checks, autosave protection, and sanitization. This is the correct baseline for production.

Can I show the subtitle on category archives too?

Yes. Replace is_singular('post') with a broader condition, then print it in loop templates (or hook into GeneratePress archive hooks).

Will it affect SEO automatically?

Not automatically. It can improve engagement and clarity, which often helps indirectly. If you want it in meta descriptions, you’d add a specific integration.

Can I mark featured posts and show them in a homepage slider?

Yes. Use the featured query shown above, then output your slider HTML. You can also build a Gutenberg block later.

What happens if I deactivate the plugin?

Your meta data remains in the database. WordPress won’t delete it. If you reactivate, everything shows again.

Can I migrate this between sites?

Yes. Post meta exports via standard WordPress export tools only sometimes. For full migration, use a migration plugin that includes post meta.

Can I expose the subtitle in REST API?

Yes. You can register meta with register_post_meta and set show_in_rest to true. That’s useful for headless builds.

Can I make the Featured checkbox a custom post status instead?

Yes, but post status changes can affect visibility and editorial workflows. Post meta is often the simplest “editor pick” system.


A subtitle helps humans decide faster. A featured toggle helps you curate better. When you combine them, your site feels more intentional.

Keep subtitles short. Keep featured posts limited. Make “Featured” mean something. That’s how you create trust with readers over time.


⚠️ Disclaimer and Source Hygiene


This tutorial is provided for educational purposes and general WordPress development guidance. Always test code on a staging site first and keep backups before making changes. Information is based on standard WordPress best practices and widely accepted secure coding patterns from authoritative documentation and developer references.

🔔 For more tutorials like this, consider subscribing to our blog.
📩 Do you have questions or suggestions? Leave a comment or contact us!
🏷️ Tags: WordPress meta box, WordPress plugin development, GeneratePress child theme, post subtitle WordPress, featured posts WordPress, WordPress custom fields, Gutenberg sidebar meta box, WordPress security nonce, WP_Query meta query, WordPress admin columns
📢 Hashtags: #WordPress #WordPressPlugin #GeneratePress #WebDevelopment #WPDev #Gutenberg #TechnicalSEO #BloggingTips #WPSecurity #TokyoBlade


📚 Sources and References

WordPress Developer Documentation and Best Practices
WordPress Developer Resources for meta boxes, post meta, capability checks, nonces, and save_post hooks
WordPress sanitization and escaping best practices for secure output and storage
WP_Query documentation for meta queries and performance considerations


🕊️ Secondary Sources and Testimonials

Experienced WordPress developers generally recommend class-based plugin structure for stability and namespace safety
Common editorial workflows in WordPress publishing use post meta “featured” flags to curate homepage sections without changing post status
GeneratePress hook-based output is widely used for clean theme customization without template overrides

Report an issue (max 5 words):

We store the message, post link, time, and IP (for abuse prevention). No account required.

Want to support us? Let friends in on the secret and share your favorite post!

1 online now

Live Referrers

No external referrers recorded for this post.

Photo of author

Flo

HZ Post Enhancer: Subtitle + Featured Meta Box

Published

Update

Welcome to HelpZone.blog, your go-to hub for expert insights, practical tips, and in-depth guides across technology, lifestyle, business, entertainment, and more! Our team of passionate writers and industry experts is dedicated to bringing you the latest trends, how-to tutorials, and valuable advice to enhance your daily life. Whether you're exploring WordPress tricks, gaming insights, travel hacks, or investment strategies, HelpZone is here to empower you with knowledge. Stay informed, stay inspired because learning never stops! 🚀

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.