Let’s get started
Take your business to next level
Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.
WP Statistics keeps track of every visit to your WordPress site. You can surface this data in a “Top Pages” list for your visitors—or just for yourself—using one of the two approaches below.
Best for site owners who prefer configuring through the WordPress admin UI.
wp_statistics_get_top_pages()
in Your Theme / Plugin CodeBest for developers who need full control over markup or want to embed the list in custom templates.
array wp_statistics_get_top_pages(
string|null $rangestartdate = null, // 'YYYY-MM-DD'
string|null $rangeenddate = null, // 'YYYY-MM-DD'
int|null $limit = null, // max items (default 5)
string|array|null $post_type = null // 'post', 'page', ['post','product'], etc.
)
Returns an array of rows, one per page:
[
[0] => uri (string) // e.g. '/about-us/'
[1] => views (int) // total or range‑limited count
[2] => page_id (int) // WordPress post ID
[3] => title (string) // up to 200 chars
[4] => url (string) // absolute permalink
]
Parameter | Required | Description |
---|---|---|
$rangestartdate | No | Start of the period to analyse (inclusive). Use null for “all‑time.” |
$rangeenddate | No | End of the period (inclusive). Must be supplied if you pass a start date. |
$limit | No | Maximum number of pages to return. Defaults to 5. |
$post_type | No | A single post type ('post' ) or an array (['post','product'] ). null = all types. |
// Show this month’s 10 most‑viewed blog posts
$top_posts = wp_statistics_get_top_pages(
date('Y-m-01'), // first day of current month
date('Y-m-d'), // today
10, // limit
'post' // post type
);
if ( $top_posts[1] ) {
echo '<ol class="top-posts">';
foreach ( $top_posts[1] as $page ) {
[$uri, $views, $id, $title, $link] = $page;
printf('<li><a href="%s">%s</a> <span class="views">%d views</span></li>',
esc_url($link), esc_html($title), $views);
}
echo '</ol>';
}
'product'
) or an array of slugs.Become part of our growing family of +600,000 users and get the tools you need to make smart choices for your website. Simple, powerful insights are just a click away.