---
title: "WordPress : La fonction – if is post type –"
id: "787"
type: "post"
slug: "if-is-post-type"
published_at: "2014-11-27T15:47:09+00:00"
modified_at: "2023-04-13T11:45:48+00:00"
url: "https://www.mistersize.com/blog/if-is-post-type/"
markdown_url: "https://www.mistersize.com/blog/if-is-post-type.md"
excerpt: "Afficher un contenu selon le type de post sur WordPress. 2 solutions : 1. Directement dans le template : <?php $post_type = get_post_type( $post ); if( $post_type == 'services') { ?> // DO SOMETHING <?php } ?> 2. Ou, en..."
taxonomy_category:
  - "Blog"
taxonomy_post_tag:
  - "WordPress"
---

[j'aime](#partage)
[Commenter](#comments-list)
Taggué dans : [WordPress](https://www.mistersize.com/tag/wordpress/)

Afficher un contenu selon le type de post sur WordPress. 2 solutions :

### 1. Directement dans le template :

```
 <?php $post_type = get_post_type( $post );
 if( $post_type == 'services') { ?>

 // DO SOMETHING 

 <?php } ?>
```

### 2. Ou, en passant par une fonction :

Dans functions.php :

```
// in functions.php
function is_post_type($type){
    global $wp_query;
    if($type == get_post_type($wp_query->post->ID)) return true;
    return false;
}
```

et dans votre thème :

Besoin d’un spécialiste **WordPress** pour votre projet ? [Contactez-moi](https://www.mistersize.com/contact/)

```
// in template
if (is_single() && is_post_type('post_type')){
  //work magic
}
```
