Paramètres

$post_columns

(string[]) Tableau associatif des en-têtes de colonne.

$post_type

(string) Slug du type de post.

Où trouver le hook manage_posts_columns dans le CMS Wordpress

Exemples

Si la nouvelle colonne personnalisée est seulement pour le type de post par défaut, il faut vérifier le type de poste.
<pre class="code"><code class="langage-php"><span class="b-fn">function</span> my_add_new_columns(<span class="b-php">$columns</span>) {
    <span class="b-php">$post_type</span> = get_post_type();
    <span class="vert">if</span> ( <span class="b-php">$post_type</span> == <span class="r-php">'post'</span> ) {
        <span class="b-php">$new_columns</span> = <span class="vert">array</span>(
            <span class="r-php">'my_featured'</span> => esc_html__( <span class="r-php">'Featured'</span>, <span class="r-php">'text_domain'</span> ),
        );
        <span class="vert">return</span> array_merge(<span class="b-php">$columns</span>, <span class="b-php">$new_columns</span>);
    }
}
add_filter( <span class="r-php">'manage_posts_columns'</span>,  <span class="r-php">'my_add_new_columns'</span> );</code></pre>
Cet exemple va supprimer l'auteur, les catégories, les étiquettes et les commentaires des colonnes
<pre class="code"><code class="langage-php"><span class="vert">if</span> ( ! <span class="b-fn">function</span>_exists( <span class="r-php">'custom_manage_posts_column'</span> ) ) {
    <span class="b-fn">function</span> custom_manage_posts_column( <span class="b-php">$columns</span> ) {
        unset( <span class="b-php">$columns</span>[<span class="r-php">'author'</span>] );
        unset( <span class="b-php">$columns</span>[<span class="r-php">'categories'</span>] );
        unset( <span class="b-php">$columns</span>[<span class="r-php">'tags'</span>] );
        unset( <span class="b-php">$columns</span>[<span class="r-php">'comments'</span>] );
        <span class="vert">return</span> <span class="b-php">$columns</span>;
    }
}
<span class="vert">if</span> ( has_filter( <span class="r-php">'manage_posts_columns'</span> ) ) {
    add_filter( <span class="r-php">'manage_posts_columns'</span>, <span class="r-php">'custom_manage_posts_column'</span> );
}</code></pre>

Sources

Codex Wordpress : manage_posts_columns

Autres hooks dans le même fichier : wp-admin/includes/class-wp-posts-list-table.php

Retour