wordpress snippets last updated   : September 29, 2014
we now have 639 snippets
category functions.php

Prepend ‘Sponsored post:’ to post title using post_meta

wordpress snippet

Simple little snippet that will use a custom field sponsored set to true will prepend “‘Sponsored post:” to the_title. The second snippet will prepend the value of sponsored to the_title.

read more

Update: Automatically create media_buttons for shortcode selection

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will add a select menu with an automatically generated list of your shortcodes. For everyone that is going to say hey wait a minute you posted this snippet before! Yes this is true but I added a few updates to this version.

read more

Remove image sizes from media upload gallery

wordpress snippet

This snippet will let you remove image sizes from media upload gallery very similar to a recent post that will show you how to add custom image sizes to the media upload gallery.

read more

Add featured image to RSS feed

wordpress snippet

It’s often useful to spruce up your RSS feed with images and the simplest way to do this is to include your post’s featured image in the feed content. Some themes have an option to enable this, but if yours does not then you can use this snippet. It will display the image to the right of the first paragraph of your content, but you can change the CSS in the snippet to modify the layout.

read more

Automatically link twitter usernames in posts

wordpress snippet

Excellent snippet by Paul Underwood that will automatically link twitter usernames in your posts. This snippet will look for text like @wpsnipp and convert it to <a href="http://twitter.com/wpsnipp">@wpsnipp</a> something I’m sure many of you will find useful.

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