Last Viewed Posts


This plugin displays the posts (and pages) that have been recently viewed by the visitor (single view).

The posts are saved in a cookie and by default the last 10 posts that have been visited are displayed.

Note that this is NOT a global listing of recently viewed posts by all users! Nothing is stored in the database.

Every vistor has their own unique listing of the single posts that they have viewed.

If cookies are not accepted or no single post has been clicked, no output will be displayed.

The plugin comes with a widget and a template tag.

This plugin has been adopted and maintained by WPBeginner

What’s Next

If you like this plugin, then consider checking out our other projects:

  • OptinMonster – Get More Email Subscribers with the most popular conversion optimization plugin for WordPress.
  • WPForms – Best Drag & Drop WordPress Form plugin (over 1 million active installs).
  • MonsterInsights – See the Stats that Matter and Grow Your Business with Confidence. Best Google Analytics Plugin for WordPress.
  • SeedProd – Jumpstart your website with the #1 Coming Soon & Maintenance Mode Plugin for WordPress.
  • WP Mail SMTP – Improve email deliverability for your contact form with the most popular SMTP plugin for WordPress.

Visit WPBeginner to learn from our WordPress Tutorials and find out about other best WordPress plugins.


Viewed posts are always tracked as long as the plugin is active and the visitor has enabled the cookies.

Download and unzip the plugin file. Upload last_viewed_posts.php to your /wp-content/plugins/ directory.
Go to the admin backend and activate the plugin.

To display the list, you can use the widget that comes with the plugin or use the following code and place it anywhere you want to, but outside the loop, e.g. sidebar.php :

Last viewed posts

The single template tag is shown below, but I recommend to use the code shown above.
It prevents you from displaying a blank list if the visitor has cookies disabled or did not view any single post yet.

By default the cookie expires after 360 days, the number of entries that are displayed is 10 and pages are recognized.
To change these values, edit the last_viewed_posts.php between the equals sign and the semicolon:

$zg_cookie_expire = 360; // After how many days should the cookie expire? Default is 360.
$zg_number_of_posts = 10; // How many posts should be displayed in the list? Default is 10.
$zg_recognize_pages = true; // Should pages to be recognized and listed? Default is true.


Last Viewed Posts はオープンソースソフトウェアです。以下の人々がこのプラグインに貢献しています。


“Last Viewed Posts” をあなたの言語に翻訳しましょう。

開発に興味がありますか ?

コードを閲覧するか、SVN リポジトリをチェックするか、開発ログRSS で購読してみてください。



  • Updated Readme.txt.
  • Checked compatibility with WordPress 5.1.1.
  • Miscellaneous updates.


  • Plugin maintainance update.


  • Post/Page ID values in cookie are sanitized for output. Upgrade is recommend for more security.


  • Pages can now be recognized (optional).
  • Custom Loop is not longer used. Now we make a database query to get the post title.