Check if current post type is a custom post type – WordPress


/ Published in: PHP
Save to your folder(s)

Check if current post type is a custom post type – WordPress.
Returns a true/false-statement.

Can be used outside The Loop.


Copy this code and paste it in your HTML
  1. function is_custom_post_type() {
  2.  
  3. global $wp_query;
  4.  
  5.  
  6. $post_types = get_post_types(array('public' => true,'_builtin' => false),'names','and');
  7.  
  8. foreach ($post_types as $post_type ) {
  9. if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) {
  10. return true;
  11. } else {
  12. return false;
  13. }
  14. }
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.