Skip to main content
Snippets

Retrieve the post type and ID of the current post

By March 9, 2016No Comments

Often times I want to target CSS class or ID for a given post type, be it a page, post, archive, or custom post. This allows more control over styling, and obviously can be used in PHP for writing conditional statements.

The example below will output the numeric ID of the current post as well as the post type. An example would be something like class=”21 portfolio”

 the_ID(); echo ' '.get_post_type(); 

get_the_ID()

get_post_type()

Contact us to learn more about Adopt the Web for your business

Author Jarod Thornton

More posts by Jarod Thornton