• Resolved Alex Kladov

    (@prowebassist)


    Hi,

    Is it possible to set a custom Admin Column name for a Taxonomy using CPT UI? I can set a custom Menu name, which is great, but I can’t find how to set a custom Admin Column name anywhere.

    If it’s not already a part of your awesome plugin, can you please consider adding it?

    It’s necessary, because otherwise Admin Column name for each taxonomy can become unreasonably long. For example, in WooCommerce they have Product categories taxonomy, which is named “Product categories” everywhere, except in Menu & Admin Column, where it’s simply “Categories”. Which is handy, since it keeps the admin columns & menu nice and short, while still being more specific (i.e. “Product categories”), when dealing with that taxonomy name elsewhere on the site (since we can have other post types with their own “categories”, so we need a full name to differentiate between them). Here is what I’m talking about:
    WooCommerce Products admin page

    It becomes worse, when you have a long-ish CPT name + a long-ish Taxonomy name. The column name just gets out of control. Here is an example from one of the sites I’m working on:
    CPT Admin Columns

    As you can see from the screenshot above, it would be awesome, if we could either (a) make Admin Column name inherit custom Menu name, if one has been set or (b) add an option to add a custom Admin Column in Taxonomy configuration settings (c) combine a & b, where we can set the Admin Column name in settings or, if left blank, it would inherit Menu name by default.

    Cheers,
    Alex

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Alex Kladov

    (@prowebassist)

    I just noticed that in the 2nd screenshot I highlighted the wrong Menu item – “Technical Skills”. I meant to highlight “Categories” instead, pointing to “Team Member categories” column.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Unless I’m mistaken and those can be customized via the standard labels options available to register_post_type() and register_taxonomy() it’s probably not possible with CPTUI as is. We focus on being as great of a UI as we can be to handle what gets passed to those two functions.

    With that said, I’m not sure how easy and accessible amending and filtering those spots would be, if possible at all via plugin. I’d need to try and dig into core to see, and then evaluate how easy it’d be. That said, I’m also not set on the idea of adding anything for this as part of the free plugin here. Tutorial? Sure, I’d write one up, but we try to keep CPTUI’s focus pretty straightforward.

    Thread Starter Alex Kladov

    (@prowebassist)

    I see what you mean. The get_taxonomy_labels() doesn’t seem to have an option for an Admin Column label by default, which is a shame.

    Seems like it would be super simple to tap into the taxonomy_labels_{$taxonomy} filter to add a taxonomy admin column label item into the labels array and then manage_{$post_type}_posts_columns filter to display it.

    But I understand, if it doesn’t fall into the scope of your plugin & if you wouldn’t want to add this functionality.

    I do think it would’ve added a nice little touch, since it’s a shame that the admin column names for taxonomies get so unwieldy.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If anything, I’d probably add it more to our docs area currently seen at https://docs.pluginize.com/category/126-custom-post-type-ui at least once worked out some sample code to work with.

    Thread Starter Alex Kladov

    (@prowebassist)

    Here is what I’ve done. Didn’t even need to use the taxonomy_labels_{$taxonomy} filter, cos that just adds unnecessary complexity. Everything can be done just with manage_{$post_type}_posts_columns.

    The code below requires at PHP 5.3+, because I used PHP closures to make the code more re-useable.

    
    function define_cpt_taxonomy_admin_column_names() {
      // List of CPTs that need custom columns
      $cpts = array(
        'cpt_1_slug' => array(
          'cpt_1_taxonomy_1_slug' => 'CPT 1 Taxonomy 1 Admin Column Name',
          'cpt_1_taxonomy_2_slug' => 'CPT 1 Taxonomy 2 Admin Column Name',
          'cpt_1_taxonomy_3_slug' => 'CPT 1 Taxonomy 3 Admin Column Name',
        ),
        'cpt_2_slug' => array(
          'cpt_2_taxonomy_1_slug' => 'CPT 2 Taxonomy 1 Admin Column Name',
        ),
      );
    
      // Loop through each CPT & create a filter to feed appropriate column names for each taxonomy
      foreach( $cpts as $cpt_slug => $taxonomies ) {
        foreach( $taxonomies as $taxonomy_slug => $admin_column_name ) {
          add_filter( "manage_{$cpt_slug}_posts_columns", function( $post_columns ) use ( $taxonomy_slug, $admin_column_name ) {
            $post_columns["taxonomy-{$taxonomy_slug}"] = $admin_column_name;
    
            return $post_columns;
          }, 10, 3 );
        }
      }
    }
    define_cpt_taxonomy_admin_column_names();
    

    The only thing someone will need to modify is $cpts array to provide a list of desired custom post types, with their list taxonomies that need custom Admin Column names.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    5.3+ should be no issue for at least people using current CPTUI, as we have a minimum requirement of PHP 5.6

    Looks legit otherwise. Thanks for typing up what you used, and hopefully it proves helpful for someone else.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom title for Taxonomy admin column name’ is closed to new replies.