wordpress snippets last updated   : October 6, 2014
we now have 641 snippets
category functions.php

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

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

Insert calendar into wp_nav_menu

wordpress snippet

Needed this for a recent project as a client wanted to display the wordpress calendar as a dropdown item within the menu. Add this snippet to the functions.php of your wordpress theme will add a new menu item to your wp_nav_menu that has a submenu calendar.

read more

Change title attribute of wordpress login logo

wordpress snippet

This little snippet will change the title attribute text when you hover over the wordpress logo on the login page. If you want to replace the logo take a look at this snippet it will remove the wordpress logo.

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
jqsnipp.com | we just launched jquery snippets website