Check for custom post types – WordPress

If you work with WordPress themes and Custom Post Types you will love the snippet below.

This is a conditional check for custom post types within The Loop:

If you want to use the snippet outside the loop you just need to pass the post ID:

Learn more about the get_post_type function.

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.