Did you ever wonder how websites like Amazon show you recently viewed items even when you are not logged in? Most online shopping sites use cookies to display recently viewed items to their users. This helps users review their options, compare products, and revisit items they liked. In this article we will show you how to display last visited posts to a user in WordPress. The goal is to keep users interested, remind them of usefulness of your website and build brand recognition.
First thing you need to do is to install and activate the Last Viewed Posts plugin. After activating the plugin, go to Appearance » Widgets. Drag and drop Last Viewed Posts widget to your sidebar and it will immediately start showing posts a user last viewed.
This plugin uses cookies to keep track of posts a user has viewed on your website. This cookie expires in 360 days, but you can change that by editing the code. Go to Plugins » Editor and select Last Viewed Posts from plugin edit drop down. Find the parameters and edit them to suit your needs:
/* Here are some parameters you may want to change: */ $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.
We would recommend 60 days for cookie expiration, and 5 posts to be displayed in the list. If you just want to show the last visited post then set the number of posts to 1. It is also advised that you inform users about cookie usage on your site in your privacy policy page. We hope that this article helps you build a loyal user base. For question and feedback please leave a comment.
Any new plugins to show recently viewed post in a carousel format?.
Is this plugin still maintained? I’m looking for this exact functionality. Thanks!
Is there a way to do this to have it highlighted next to the post title rather than in a widget?
This is a fantastic little gem. Is there a way to make this display other (custom) post types, or history across a multisite network?
Is there a way to show the whole post (i.e. get_post) instead of just the title? Would you be able to provide the code and the location or where to place it in the plugin code? Thanks!
I have installed the plugin but have trouble installing the widget. Go to Appearance > Widgets > Click on Last Viewed Posts> Click Primary Sidebar>Add Widget, nothing happens. If I drag and drop the Last Viewed Posts still nothing happens.
Any idea what I’m doing wrong?
Tony
Is there a shortcode for this plug in? I would like to insert this within a post.
No currently it does not have a shortcode. However, you can try our tutorial on how to add WordPress widgets in posts or page content.
This works nicely on my localhost but throws a “Cannot modify header information – headers already sent” error on the production server. Seems like content has already begun to output when you set the cookie.
I’m using Roots theme and WordPress 3.6. Any suggestions on how to solve this?
Hi this plugin is great i have a questions
can you add a image ( featured image )
thanks
Yes, but you would have to edit the plugin file.
Thank you for this lovely little plug-in. It greatly adds to the personalization experience on a site.
David.
Is the plugin on github? I’d love to contribute.
No it is not on Github yet. Please get in touch via the contact form, so we can communicate further
Wouldn’t it be better to use some kind of override in your own theme or plugin to change the value of those variables? If you edit the plugin directly, when you update the plugin(which you should always do!) you’ll lose those changes. It shouldn’t be too hard to hook in right after the plugin is activated and assign new values to what I’m assuming are global variables.
Agreed. That is in the list of things to add to that plugin when we create a settings page