wordpress snippets last updated   : July 14, 2014
we now have 634 snippets

Track post and page views by user ID, date and time

wordpress snippet

After an interesting conversation with a fan of wpsnipp, I come up with something to track unique post views for registered users. However this neat little snippet does a little more than that. First add wps_trackViewDates(); within the loop of your single.php template file. Once this has been added, the snippet will track the ID of the user that viewed an individual post along with the date and time it was viewed.

read more

Navigate next, previous adjacent post with jquery and the left, right keys

wordpress snippet

If you are using adjacent post relational links in the head of your wordpress theme add this little bit of jquery. This will let people navigate next, previous adjacent post with the left and right arrow keys.

read more

Display posts in a random order, but retain persistent pagination

wordpress snippet

Randomising the order of the returned posts in a WordPress query is easy – simply add 'orderby' => 'rand' to the arguments and you’re good to go – this is great, until you need to paginate the results. As soon as you navigate to the second page of the results, the posts are returned randomly once again and you get an entirely different set of posts that may or may not contain posts that you have already viewed – if you’ve experienced this before then you’ll know exactly how frustrating it can be. The first thing we need to do is make sure our PHP session is initiated and then we can use the 'posts_orderby' filter to handle the persistent randomisation.

read more

Add post category to body_class on single posts

wordpress snippet

This little snippet will take all the categories assigned to a post and add them to the body_class “sgl-cat-{category-name}”.

read more

Enable google docs shortcode for .pdf documents

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will setup [pdf] shortcode to link PDF documents to Google docs online viewer.

read more

Give author capabilities including editing other authors posts

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will allow authors to edit other users posts.

read more
jqsnipp.com | we just launched jquery snippets website