Skip to content

Custom Taxonomy Columns

Henner Renardi Setyono edited this page Mar 17, 2025 · 4 revisions
px_override_taxonomy_columns($taxonomy_name, $columns);

Override all of the Taxonomy's columns.

PARAMETER

$taxonomy_name (string)

$columns (array) - Collection of column's array in $slug => $args format. $slug is unique key and has some reserved name. Each $args contains:

  • label (string) - The column's title. Default is the titleized slug.

  • content (callable) - Callback to return string content. Accepts two parameters:

    • $term (WP_Term)
    • $fields (array) - all custom fields, will use ACF if installed.
  • sortable (boolean) - Whether the column can be sorted or not. Can only sort by alphabet or number. To sort date, it can only sort YYYY-MM-DD format

  • icon (string) - Replace the column name with Icon from dashicons.

EXAMPLE

px_override_taxonomy_columns('product_brand', [
  'name' => [
    'label' => 'Name',
  ],
  'icon' => [
    'label' => 'Icon',
    'content' => function($term, $fields) {
      if (isset($fields['logo'])) {
        $icon_src = $fields['logo']['sizes']['thumbnail'];
        $content = "<img src='{$icon_src}' width='30'>";
        return $content;
      }
      return '-';
    }
  ],
  'description' => [
    'label' => 'Description',
  ],
  'posts' => [
    'label' => 'Count',
  ],
]);

Reserved Column Slugs

Using one of the reserved slug means the content is automatically populated. They are:

  • name
  • description
  • slug
  • posts - Number of posts with this term.

Clone this wiki locally