How to Show Top 3 Most Viewed Posts WordPress Dashboard

⏲️ Estimated reading time: 4 min

Most Viewed Posts in WordPress Dashboard Easily

Want to see your most popular posts at a glance? Learn how to display the top 3 most viewed posts directly in your WordPress dashboard using a simple PHP function and custom CSS for better admin insights.


Show Top 3 Most Viewed Posts in WordPress Dashboard Easily

Tracking post popularity is key to understanding what your visitors enjoy the most. But wouldn’t it be even better if you could see your most viewed content right in your WordPress dashboard without using any heavy plugins?

In this tutorial, you’ll learn how to create a lightweight and efficient PHP function to display the top 3 most viewed posts inside the admin panel. It’s simple, requires no third-party tools, and keeps your WordPress site clean and fast.


Why Add a Post Views Widget in the Dashboard?

Many site owners use analytics platforms like Google Analytics or Jetpack to see traffic stats. However, these tools don’t always show quick insights directly in your WordPress backend.

Adding a custom dashboard widget to show the top viewed posts offers several benefits:

  • Instant visibility on your site’s best content
  • Encourages content updates based on performance
  • Helps editors and authors focus on high-impact articles

Step-by-Step: Code to Add Top 3 Most Viewed Posts Widget

Paste the following code into your functions.php file of your child theme or use a custom plugin:

function top_3_posts_dashboard_widget() {
    wp_add_dashboard_widget(
        'top_3_posts_views_widget',
        '🔥 Top 3 Most Viewed Posts',
        'display_top_3_posts_views'
    );
}
add_action('wp_dashboard_setup', 'top_3_posts_dashboard_widget');

function display_top_3_posts_views() {
    $top_posts = new WP_Query(array(
        'posts_per_page' => 3,
        'meta_key' => 'post_views_count',
        'orderby' => 'meta_value_num',
        'order' => 'DESC',
        'post_type' => 'post',
        'post_status' => 'publish'
    ));

    if ($top_posts->have_posts()) {
        echo '<ul class="top-posts-list">';
        while ($top_posts->have_posts()) {
            $top_posts->the_post();
            $views = get_post_meta(get_the_ID(), 'post_views_count', true);
            echo '<li><a href="' . get_edit_post_link() . '">' . get_the_title() . '</a> <span class="views">(' . intval($views) . ' views)</span></li>';
        }
        echo '</ul>';
    } else {
        echo '<p>No data available.</p>';
    }

    wp_reset_postdata();
}

Add Admin CSS for Better Styling

To enhance the appearance of the list in the dashboard, add this CSS using the admin_head hook:

function top_posts_widget_custom_css() {
    echo '<style>
        #top_3_posts_views_widget .top-posts-list {
            margin: 0;
            padding-left: 1em;
        }
        #top_3_posts_views_widget .top-posts-list li {
            margin-bottom: 8px;
            font-size: 14px;
        }
        #top_3_posts_views_widget .top-posts-list a {
            font-weight: bold;
            text-decoration: none;
            color: #0073aa;
        }
        #top_3_posts_views_widget .top-posts-list a:hover {
            text-decoration: underline;
        }
        #top_3_posts_views_widget .views {
            color: #555;
            font-style: italic;
            margin-left: 6px;
        }
    </style>';
}
add_action('admin_head', 'top_posts_widget_custom_css');

How to Show Top 3 Most Viewed Posts WordPress Dashboard

Bonus: How to Track Post Views

If you’re not yet tracking views per post, here’s a basic tracker to insert in your theme:

function track_post_views($post_id) {
    if (!is_single()) return;

    $views = get_post_meta($post_id, 'post_views_count', true);
    $views = $views ? intval($views) + 1 : 1;
    update_post_meta($post_id, 'post_views_count', $views);
}
add_action('wp_head', function () {
    if (is_single()) {
        global $post;
        if ($post instanceof WP_Post) {
            track_post_views($post->ID);
        }
    }
});

This will increment the post_views_count every time a single post is viewed.


Adding this functionality is an excellent way to improve editorial oversight and content strategy. You’ll quickly identify high-performing articles and optimize others accordingly. Plus, it keeps your dashboard more informative without the need for bloated plugins.


📩 Do you have questions or suggestions? Leave a comment or contact us!
🏷️ Tags: WordPress tips, dashboard widgets, PHP snippets, top posts, post views, WordPress admin, WordPress tutorial, developer tools, content strategy, WP functions
📢 Hashtags: #WordPress #WPAdmin #TopPosts #DashboardWidget #PHPCode #WPDevelopment #PostViews #WPPlugin #WebDev #ContentMarketing

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 Show Top 3 Most Viewed Posts WordPress Dashboard

Published

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