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

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 custom image sizes to media insert dialog box with image_size_names_choose

wordpress snippet

With this little snippet you can add custom image sizes to media insert dialog box. image_size_names_choose allows modification of the image size lists so that you can place a custom option within the media library.

read more

Stop Disqus from outputting JS on anything but single posts or pages

wordpress snippet

Disqus outputting JS on parts of your wordpress website you don’t want? Adding this snippet to the functions.php of your wordpress theme will only output JS on is_singular posts or pages where comments are available.

read more

Use wp_trim_words to trim your text in wordpress

wordpress snippet

WordPress 3.3+ has a core function called wp_trim_words() this function will trim text to a specified number of words and return the result. Adding this snippet to your wordpress loop will let you easily trim the number of words displayed within the_content, the_excerpt, the_title or any other value you pass to this core function.

read more

Attach PDF files to post with custom metabox file selection

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will create a new metabox within your post editing screen with a select menu listing all PDF files. Adding the second snippet in your wordpress template in the location you wish to display the files URL.

read more

Change admin post/page color by status – draft, pending, published, future, private

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will change the background colors of the post / page within the admin based on the current status. Draft, Pending, Published, Future, Private.

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