wordpress snippets last updated   : January 29, 2015
we now have 646 snippets

Register taxonomy for your pages

wordpress snippet

This is a simple snippet that will register a custom taxonomy for pages. In the sample code I register a taxonomy called things but of course you would want to register something a little more realistic. You can find out more details about registering a custom taxonomy in the codex. Just add this snippet to the functions.php of your wordpress theme and you will see the new taxonomy displayed within the wordpress admin.

read more

Create custom terms admin column

wordpress snippet

create-custom-terms-admin-column

This is a simple little snippet that will add your custom terms in an admin column. I added both the filter and action for both posts and pages, feel free to use both or choose one. Add this snippet to the functions.php of your wordpress theme but be sure to change TERM_NAME on this line echo the_terms( $id, 'TERM_NAME', '', ', ' ) in the snippet to the name of your term. You will then see your terms displayed exactly the same way as you see categories displayed within the admin section.

read more

Remove the_post_thumbnail class

wordpress snippet

Have you ever been using the_post_thumbnail( 'thumbnail' ); but wanted to remove the class that is automatically added. Add the following snippet to the functions.php of your wordpress theme to automatically remove any class. Simple but effective,

read more

count_user_posts by user ID and by post_type

wordpress snippet

You may be aware that count_user_posts has been around since about 3.0. However as of 4.1 you are able to optionally define a post_type. This is a perfect little snippet if you have a blog with multiple post types and you wanted to show specific counts for authors. I could use something like this for WordPress snippets vs tutorials sections and it would be perfect. Just add this snippet in the template you wish to display the count and you are ready to go.

read more

Customize Comment Count Text

wordpress snippet

You can customize the text for displaying the number of comments inside the loop. This is just a simple template edit however it is extremely useful if you are creating a theme that is not a traditional theme or you wanted to inject a little bit of personality into the site.

read more

Show or Hide widgets on specific pages

wordpress snippet

Want to show or hide widgets on specific pages? This is a great little snippet contributed by Joel Worsham that will do just that. You will first need to get the id name of the widget that you wish to define. You can do this be viewing the page source or using a web inspector tool to view the widget id. The current sample is setup to only display the core ‘pages’ widget on the contact page only. Don’t forget that is_page also accepts an array of page names and id’s.

read more