wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

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

Add plugin settings link to plugins list table

wordpress snippet

When building a plugin that has its own settings page, it’s often handy to create a link to the settings page straight from the Plugins page in the dashboard – this saves users the time it takes to find where exactly your plugin appears in the admin menu. Here is a simple code snippet that creates the settings link for you – all you need to do is set the link to point to the right place. This code must be placed in your plugin’s index file.

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

Post Meta.. The most valuable resources

tutorials
disable-wordpress-automatic-updates

Now that you have a decent understanding of meta data, how to save it and display it, let’s review some good tools for helping us manage the display and saving of our meta data.

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