How to Add Dashboard Widget For Posts Missing Excerpt

⏲️ Estimated reading time: 5 min


Posts Missing Excerpt Dashboard Widget

How to Add It in WordPress. This tutorial shows you how to add a custom WordPress dashboard widget that lists all posts missing excerpts, helping you improve SEO and content quality directly from your admin panel. Includes full PHP code and setup guide.


When managing a blog with dozens or hundreds of posts, it’s easy to forget to add excerpts. Missing excerpts can negatively affect your SEO and click-through rates in search engines.
To make this process easier, you can add a WordPress dashboard widget that instantly shows you which posts have no excerpt and even lets you edit them directly.

In this tutorial, you’ll learn how to:

  • Count all posts without excerpts.
  • Display them in the WordPress dashboard.
  • Quickly access the edit page to fix them.

Why Are Missing Excerpts Important?

An excerpt is a short summary of your post, used in:

  • Search results snippets.
  • Social media previews.
  • Your theme’s post listing pages.

Without an excerpt, WordPress will try to auto-generate one by taking the first few words of your content but this is often less engaging and bad for SEO. Writing a custom excerpt gives you full control over what users see before clicking.


The PHP Code

Below is the complete code for adding the widget.
You can place it inside your functions.php file or in a custom plugin.






<?php
/**
 * Dashboard Widget: Posts Without Excerpt (WP_Query version) Title turns red if missing excerpts
 */
add_action('wp_dashboard_setup', 'hz_dashboard_posts_no_excerpt');

function hz_dashboard_posts_no_excerpt() {
    global $wpdb;

    // Numărăm postările fără excerpt
    $count = (int) $wpdb->get_var("
        SELECT COUNT(*) 
        FROM {$wpdb->posts} 
        WHERE post_type = 'post' 
        AND post_status = 'publish' 
        AND post_excerpt = ''
    ");

    $title = 'Posts Without Excerpt';
    if ($count > 0) {
        $title .= ' (' . $count . ')';
    }

    wp_add_dashboard_widget(
        'hz_posts_no_excerpt_widget', // Widget ID
        $title,                       // Widget Title
        'hz_posts_no_excerpt_display' // Callback function
    );

    // Dacă lipsesc excerpt-uri, colorează titlul în roșu
    if ($count > 0) {
        add_action('admin_head-index.php', function () {
            echo '<style>#hz_posts_no_excerpt_widget .hndle{color:#d32f2f !important;}</style>';
        });
    }
}

function hz_posts_no_excerpt_display() {
    global $wpdb;

    // Query all posts with empty excerpt
    $posts = $wpdb->get_results("
        SELECT ID, post_title 
        FROM {$wpdb->posts} 
        WHERE post_type = 'post' 
        AND post_status = 'publish' 
        AND post_excerpt = ''
        ORDER BY post_date DESC
    ");

    if (empty($posts)) {
        echo '<p>✅ All posts have excerpts!</p>';
    } else {
        echo '<p>The following posts have no excerpt:</p>';
        echo '<ul style="list-style: disc; margin-left: 20px;">';
        foreach ($posts as $post) {
            $edit_link = get_edit_post_link($post->ID);
            echo '<li><a href="' . esc_url($edit_link) . '">' . esc_html($post->post_title ?: '(no title)') . '</a></li>';
        }
        echo '</ul>';
    }

    // Footer note with HelpZone link
    echo '<p style="margin-top:15px; font-size:13px; color:#555;">
            🛠️ Visit <a href="https://helpzone.blog" target="_blank">HelpZone</a> for more WP tools.
          </p>';
}



How This Works

  1. wp_dashboard_setup Hook
    This hook allows you to register a custom dashboard widget.
  2. Counting Posts Without Excerpts
    Using $wpdb->get_var() we query the database to find all posts where the post_excerpt field is empty.
  3. Dynamic Widget Title
    If there are posts missing excerpts, the widget title will show the number in parentheses.
  4. Listing the Posts
    The second query fetches all posts with missing excerpts, ordered by their publication date. Each post title links to its edit page, so you can fix it quickly.
  5. Empty State Message
    If all posts have excerpts, it shows a friendly “✅ All posts have excerpts!” message.

How to Add This to Your Site

You have two main options:

Option 1: Add to functions.php

  1. Go to Appearance → Theme File Editor.
  2. Open the functions.php file of your child theme.
  3. Paste the code at the bottom.
  4. Save the changes.

Option 2: Create a Simple Plugin

  1. Create a new folder in /wp-content/plugins/ named posts-no-excerpt-widget.
  2. Inside, create a file called posts-no-excerpt-widget.php.
  3. Add this header at the top of the file: <?php /* Plugin Name: Posts Without Excerpt Widget Description: Displays a dashboard widget listing all posts without excerpts. Version: 1.0 Author: Your Name */
  4. Paste the full code below it.
  5. Activate the plugin in Plugins → Installed Plugins.

Advantages of Using This Widget

  • Instant Overview: No need to manually check each post.
  • SEO Boost: Helps ensure all posts have optimized summaries.
  • Time-Saving: Edit directly from the dashboard list.
  • Better User Experience: Excerpts improve how posts appear in archives and previews.

Possible Improvements

You could expand this widget to:

  • Filter by category – see missing excerpts per topic.
  • Bulk edit support – add excerpts without opening each post.
  • Highlight posts older than X days with no excerpt.

Final Thoughts

If you want to maintain a high-quality blog, this Posts Without Excerpt dashboard widget is a small but powerful addition.
It ensures you never forget to optimize your posts for search engines and readers, keeping your content professional and engaging.


🔔 For more tutorials like this, consider subscribing to our blog.
📩 Do you have questions or suggestions? Leave a comment or contact us!

🏷️ Tags: wordpress dashboard widget, missing excerpt checker, wordpress seo tips, wordpress admin customization, wp dashboard tools, content optimization, wordpress plugin tutorial, wordpress functions php, seo content writing, wordpress tips and tricks

📢 Hashtags: #WordPress #SEO #DashboardWidget #ContentOptimization #WebDevelopment #WPAdmin #BloggingTips #PHP #WordPressPlugins #WebsiteManagement

Report an issue (max 5 words):

Only logged-in users can submit reports.


Discover more from HelpZone

Subscribe to get the latest posts sent to your email.

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

Photo of author

Flo

How to Add Dashboard Widget For Posts Missing Excerpt

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! 🚀

👍 Like us on Facebook!

Closing in 10 seconds

Leave a Reply