Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

WordPress does not include a built-in view counter or “most viewed posts” block. To display popular posts, use a plugin that records and ranks views, or add custom PHP that stores counts in post meta and queries them numerically. For most site owners, a dedicated popular-posts plugin is the safer option; custom code is best when you need complete control and can manage caching, accuracy, and maintenance.

A popular list can improve content discovery and internal linking, but it does not guarantee higher search rankings or lower bounce rates.

What “popular by views” actually measures

“Popular” can mean different things:

  • All-time views: the total recorded since tracking started. Older posts usually dominate.
  • Recent views: activity during the last 24 hours, 7 days, or 30 days. This better reflects current interest.
  • Average views per day: useful for comparing new and old posts more fairly.
  • Analytics pageviews: measurements imported from Google Analytics or another analytics platform.
  • Local WordPress views: counts recorded by a plugin or custom post-meta field.

These figures are not interchangeable. A WordPress counter and Google Analytics can legitimately disagree because of different bot filters, consent rules, sampling, cache behavior, time zones, and measurement windows.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Method 1: Use a popular-posts plugin

A plugin is usually the fastest and lowest-maintenance solution. It can handle view tracking, ranking, thumbnails, time ranges, and display locations without requiring you to maintain PHP.

Option A: WP Popular Posts

WP Popular Posts is the more direct fit when your requirement is specifically “rank posts by views.” Its listing describes ordering by views, comments, or average views per day; ranges such as the last 24 hours, 7 days, or 30 days; custom post types; thumbnails; blocks; shortcodes; template tags; REST API support; and Elementor integration.

  1. In WordPress, open Plugins → Add New.
  2. Search for WordPress Popular Posts, install it, and activate it.
  3. Configure the tracking and display settings provided by your installed version.
  4. Choose Views for a total-view ranking, or Average views per day when comparing posts of different ages.
  5. Select the required period, such as all time, the last 24 hours, 7 days, or 30 days.
  6. Set the number of posts and optionally enable thumbnails, excerpts, or view counts.

Insert the list with a block or shortcode

Use the plugin’s block in the Block Editor or Site Editor. For a block theme, go to Appearance → Editor, open the relevant template or template part, and add the popular-posts block to the sidebar or content area.

On a classic theme, you may be able to use Appearance → Widgets. However, the plugin listing warns that its older classic widget does not work well with the block-based Widgets editor introduced in WordPress 5.8. Prefer the current block or shortcode when the legacy widget does not appear or behaves incorrectly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can also place the plugin’s shortcode in a Shortcode block, a post, a page, or a widget area. The exact shortcode attributes depend on the installed version, so use the plugin’s current documentation or its settings screen rather than copying outdated attributes.

Developers can use the plugin’s wpp_get_mostpopular() and wpp_get_views() template tags in theme templates. Elementor integration is also listed by the plugin, if enabled by your installation.

Option B: MonsterInsights

MonsterInsights is better suited to sites already using Google Analytics and wanting popular content alongside broader analytics reporting. The workflow described by the source material uses the Pro edition and Dimensions Addon, so feature availability depends on the current edition, addon, connected Analytics property, and plugin interface.

  1. Install and activate MonsterInsights, then connect it to Google Analytics.
  2. Open Insights → Popular Posts → Popular Posts Widget.
  3. Choose a widget theme and configure its layout, colors, font size, and number of posts.
  4. Configure the data source or behavior. If the Google Analytics-based option requires it, create a custom Post type dimension through the Dimensions Addon.
  5. Wait for the connected data to become available. The source workflow notes that relevant data can take up to seven days after custom-dimension configuration; this is a plugin-specific limitation, not a general WordPress rule.
  6. Insert the result using automatic placement, the Popular Posts block, a sidebar widget, or a shortcode.
  7. Visit the public page in a logged-out browser and verify that the list and links display correctly.

Check the current MonsterInsights plans before buying. Do not assume a paid analytics suite is necessary if you only need a simple local top-five list.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Method 2: Add a custom PHP view counter

Custom code gives you control over the storage key, query, HTML, and placement. It is not automatically more accurate or simpler. In practice, many site owners use a code-snippet manager such as WPCode rather than editing a theme file, so this is best described as custom PHP managed through a plugin.

The implementation has four separate responsibilities:

  1. Store a numeric count under a unique post-meta key.
  2. Increment it once for each qualifying request.
  3. Query posts using numeric meta ordering.
  4. Render and escape the links and counts.

1. Track one view per qualifying request

Add this as one PHP snippet only. Do not also call the same function from wp_head, an “after content” hook, or another snippet.

<?php
/**
 * Increment the view count for a published single post.
 */
function mysite_track_post_view() {
    if ( ! is_singular( 'post' ) || ! is_main_query() ) {
        return;
    }

    $post_id = get_queried_object_id();

    if ( ! $post_id || 'publish' !== get_post_status( $post_id ) ) {
        return;
    }

    $key   = 'mysite_post_views';
    $count = (int) get_post_meta( $post_id, $key, true );

    update_post_meta( $post_id, $key, $count + 1 );
}
add_action( 'wp', 'mysite_track_post_view' );

This counts qualifying single blog-post requests, not every visitor. It may include refreshes and some automated requests, while excluding visits that never execute PHP because of caching. For a real site, consider excluding logged-in administrators and known bots according to your traffic and consent requirements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Query and display the most-viewed posts

Use meta_value_num, not meta_value. Numeric ordering prevents values such as 10 from being sorted before 2 alphabetically. WordPress requires meta_key when using this ordering mode; posts without that metadata may not be returned.

<?php
$popular_posts = new WP_Query(
    array(
        'post_type'           => 'post',
        'post_status'         => 'publish',
        'posts_per_page'      => 5,
        'ignore_sticky_posts' => true,
        'meta_key'            => 'mysite_post_views',
        'orderby'             => 'meta_value_num',
        'order'               => 'DESC',
    )
);

if ( $popular_posts->have_posts() ) :
    echo '<section class="popular-posts">';
    echo '<h2>Most Popular Posts</h2>';
    echo '<ol>';

    while ( $popular_posts->have_posts() ) :
        $popular_posts->the_post();

        printf(
            '<li><a href="%1$s">%2$s</a></li>',
            esc_url( get_permalink() ),
            esc_html( get_the_title() )
        );
    endwhile;

    echo '</ol>';
    echo '</section>';
endif;

wp_reset_postdata();

The query uses posts_per_page to limit output, restricts results to published standard posts, and ignores sticky-post ordering. The complete WP_Query reference documents these parameters.

Useful query changes

  • Show three posts: change 'posts_per_page' => 5 to 3.
  • Exclude the current post: add 'post__not_in' => array( get_the_ID() ).
  • Show pages: change 'post_type' => 'post' to 'page'.
  • Show a custom post type: replace it with the registered post-type slug.
  • Restrict to a category: add a valid category_name or cat parameter.
  • Show the count: inside the loop, retrieve (int) get_post_meta( get_the_ID(), 'mysite_post_views', true ) and output it with esc_html().

Keep tracking and display code in separate snippets. Use a child theme if you put either snippet in theme files, and test on staging before enabling it on production.

Important: caching can invalidate a custom counter

With full-page caching, the web server may return a saved HTML page without running WordPress. The page can receive visitors while the PHP increment function never runs. This makes a naïve counter incomplete or apparently stuck.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Safer choices are:

  1. Use a plugin that records views through AJAX or another cache-aware mechanism.
  2. Exclude the tracking endpoint or relevant pages from caching, accepting the performance trade-off.
  3. Use server-side aggregation or an analytics platform when measurement quality matters more than a simple local counter.

Also account for browser prefetching, link previews, crawlers, social-media bots, uptime monitors, AMP or mobile variants, repeated refreshes, logged-in editors, and consent settings. Never promise that this code counts every visitor.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

All-time lists versus trending lists

The custom example stores one cumulative number, so it can create an all-time ranking only. It cannot calculate “most viewed this week” from a single total. A genuine rolling period requires historical data—for example, daily counts in a dedicated table or a plugin that maintains time-windowed statistics.

For a new blog, an all-time list may favor established content. A recent-period or average-per-day ranking is often more useful for highlighting current or emerging articles.

Performance and maintenance

Sorting a large postmeta table by view count on every request can become expensive. Limit the result count, avoid posts_per_page => -1, cache the rendered list, and refresh it periodically instead of recalculating it on every page load. Larger publishers may need a dedicated table or analytics aggregation rather than a basic post-meta counter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a unique key such as mysite_post_views to avoid collisions. If you switch plugins, counts may not transfer automatically. Check whether the old system stores values in post meta or a custom table, identify its storage key, and confirm whether it supports export and import before deactivating it.

Troubleshooting

The list is empty

Confirm that the plugin is active or that the tracking snippet has run. With custom code, initialize the meta key to 0 when posts are published, or accept that posts without the key may be omitted by a meta-key-sorted query. Also check that posts are published and that the post type matches the query.

Counts remain at zero

Clear or bypass the page cache and test while logged out. If PHP still does not run, use a cache-aware plugin or configure an appropriate tracking endpoint. Check that the snippet is enabled and that no fatal error is preventing execution.

Counts increase twice

Search for duplicate copies of the function and remove extra hooks. Do not invoke the counter both from wp_head and from an after-content insertion. Check whether separate mobile, AMP, or translated versions also track the same visit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The order is 1, 10, 2

Use meta_key together with orderby => meta_value_num. The plain meta_value mode sorts stored values as text. See the WordPress query documentation.

The widget is missing in a block theme

Use Appearance → Editor and insert the plugin block or a Shortcode block. The legacy classic widget may not work correctly in the block-based Widgets editor.

The shortcode appears as text

Place it in a Shortcode block or a widget area that processes shortcodes. Confirm that the plugin is active and that you are using the current shortcode syntax documented by its installed version.

Counts do not match Google Analytics

This is normally expected. Compare the same date range and time zone, then account for bot filtering, consent, sampling, internal traffic, cache execution, and different definitions of a pageview.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which method should you choose?

Requirement Best fit
Fastest setup Plugin
Already using MonsterInsights and Google Analytics MonsterInsights
Direct WordPress view tracking and time ranges WP Popular Posts or another dedicated counter
Maximum markup and query control Custom code
Reliable behavior with page caching A cache-aware plugin or analytics solution
Lowest maintenance An established plugin
High-traffic custom reporting Custom development with aggregation

For most bloggers and publishers, start with a dedicated plugin and choose the measurement period deliberately. Use MonsterInsights when analytics reporting is part of the requirement. Choose custom PHP only when you can test the counter, control caching, and maintain the implementation over time.

Frequently Asked Questions

Does WordPress have a built-in popular-posts widget?

No. WordPress core does not provide a native view counter or most-viewed-posts block; you need a plugin or custom implementation.

Can a custom counter show the most-viewed posts this week?

Not from one cumulative post-meta value. Weekly or monthly rankings require historical data or a plugin that records period-specific views.

Can popular posts be displayed in a sidebar?

Yes. Use a plugin block, shortcode, supported widget, automatic placement, or theme template. Block themes use Appearance → Editor, while classic themes may use Appearance → Widgets.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can view counts be migrated between plugins?

Sometimes. Before switching, identify the old storage key or custom table and verify export/import support; counts are not automatically portable.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.