Shiba

Adventures in WordPress

  • — Home —
  • Dog
  • Art
  • Contact
  • WordPress Articles
    • WP Plugins
    • WP Programming
    • WP Admin Panels
    • WP Theme Design
    • WP How-To
    • WP Theme Images
You are here: Home / WordPress Admin / Custom Taxonomy / Modify Custom Taxonomy Columns

Modify Custom Taxonomy Columns

Tweet

by ShibaShake 13 Comments

WordPress custom taxonomies are useful for grouping wordpress posts and custom post types. For example, tags and categories are standard taxonomies provided by WordPress to group WordPress objects.

By creating our own custom taxonomies, we can creating our own groupings of posts and custom post types.

WordPress also provides a standard user interface for managing our custom taxonomy objects. For example, in the screen-shot below we show the user interface for our shiba_theme custom taxonomy object.

To the right, it displays the our list of shiba_theme objects, together with their names, descriptions, slug, and associated posts. In this case however, we use the custom taxonomy description field to store an array of data associated with our theme object.

As such, it is long and not user readable.

Standard user interface for WordPress custom taxonomies.
Standard user interface for WordPress custom taxonomies.

Therefore, we want to remove the description field and replace it with the header image associated with each theme object.

Here, we consider how to modify custom taxonomy user interface columns.

1. Create shiba_theme Custom Taxonomy

We start by creating our shiba_theme custom taxonomy object using the register_taxonomy function.

if (!is_taxonomy('shiba_theme')) {
	register_taxonomy( 'shiba_theme', 'post', 
			   array( 	'hierarchical' => FALSE, 'label' => __('Theme'),  
					'public' => TRUE, 'show_ui' => TRUE,
					'query_var' => 'theme',
					'rewrite' => array('slug' => 'theme') 
					) );
}

2. Modify Custom Taxonomy Columns

To modify our shiba_theme custom taxonomy columns, we must hook into the manage_edit-$taxonomy_columns filter.

Since our taxonomy name is shiba_theme, our filter hook becomes –
manage_edit-shiba_theme_columns

// Add to admin_init function
add_filter("manage_edit-shiba_theme_columns", 'theme_columns');	

function theme_columns($theme_columns) {
	$new_columns = array(
		'cb' => '<input type="checkbox" />',
		'name' => __('Name'),
		'header_icon' => '',
//		'description' => __('Description'),
		'slug' => __('Slug'),
		'posts' => __('Posts')
		);
	return $new_columns;
}

Line 8 – Add a header_icon column for displaying a thumbnail of the header image associated with each shiba_theme object.
Line 9 – Do no set the description column.

Step 2 - Modify Custom Taxonomy Columns
Step 2 - Modify Custom Taxonomy Columns

After we hook into manage_edit-shiba_theme_columns the description column gets removed, but our header image thumbnail still does not get rendered.

3. Render New Custom Taxonomy Column Data

To render our custom taxonomy header icon we must hook into the manage_$taxonomy_custom_column filter.

Since our custom taxonomy name is shiba_theme, our filter hook becomes –
manage_shiba_theme_custom_column

// Add to admin_init function	
add_filter("manage_shiba_theme_custom_column", 'manage_theme_columns', 10, 3);

function manage_theme_columns($out, $column_name, $theme_id) {
	$theme = get_term($theme_id, 'shiba_theme');
	switch ($column_name) {
		case 'header_icon':	
			// get header image url
			$data = maybe_unserialize($theme->description);
			$out .= "<img src=\"{$data['HEADER_image']}\" width=\"250\" height=\"83\"/>"; 
 			break;

		default:
			break;
	}
	return $out;	
}

Line 5 – Get our shiba_theme taxonomy object.
Line 6 – The $column_name here corresponds to the column names used in our theme_columns function in step 2.
Line 9 – Get the header image data associated with our shiba_theme object.
Line 10 – Concatenate the header image to our output string $out.

Once we do this, our header icon gets rendered.

Modified Custom Taxonomy Columns.
Modified Custom Taxonomy Columns.

We Are Done!

We can use the same process to add new actions for our custom taxonomy objects.

For example, in the screen-shot above we have added the actions Images and Copy to our shiba_theme objects.

Related Articles

Add Custom Taxonomy Tags to Your WordPress Permalinks

How to include taxonomy tags into our custom post type permalinks.

How to Add Admin Columns in WordPress

Many of the key administration areas within WordPress displays a table containing a list of objects and some of their attributes. We describe how to modify these administration tables.

WordPress Custom Taxonomy Input Panels

We describe registering custom taxonomies, and how to add our own custom taxonomy input interface. Substitute the default tag interface with a drop-down menu, radio button list, or something else.

Comments

  1. Daniel says

    January 20, 2017 at 3:48 pm

    Works perfectly. Thanks so much for this!

    Reply
  2. Marisa Wright says

    September 2, 2014 at 1:25 am

    I’ve used a WordPress plugin to create a custom post type and a custom taxonomy to go with it. All seems well and I’m able to create my custom posts and put them in the taxonomies – but where I’m stuck is, how do I make them show up on the site?

    I’ve tried a couple of breadcrumbs plugins but they simply ignore the custom taxonomy and post type. My theme displays normal tags and categories but ignores the custom ones. And I can’t find any explanation of how to add them in! Aaaaargh!

    Reply
    • ShibaShake says

      September 2, 2014 at 8:19 am

      Do you want to show particular custom posts based on its taxonomy? Probably easiest done by using a plugin which shows the information through a widget. I don’t use many third party plugins, so I don’t know which ones are best, but here are a couple that came up on search-
      https://wordpress.org/plugins/ultimate-posts-widget/
      http://wordpress.org/plugins/flexible-posts-widget/

      Reply
  3. Jatin says

    June 14, 2014 at 11:58 am

    Hello Friends,
    I am facing two problem in WordPress admin

    1. Load custom CSS for wp-admin on user-role base (editor)
    2. Remove some columns as per user-role in Woo-Commerce on products page

    please reply if you can understood my problem…

    Reply
  4. al says

    February 7, 2014 at 11:41 pm

    Hello Shiba,

    Thanks for a very nice tutorial.
    What file should we add the code above?

    Thanks again,

    -A

    Reply
    • ShibaShake says

      February 11, 2014 at 2:03 pm

      I add customization code through my own plugin or through a child theme. For example, the functions.php file of a theme or the main file of a plugin.
      http://codex.wordpress.org/Writing_a_Plugin
      http://codex.wordpress.org/Theme_Development

      Reply
  5. Gábor Barát says

    January 26, 2012 at 6:09 am

    Hi!

    Thank you for this great tutorial. I managed to add additional columns to my custom taxonomy. But now I would have to add a column which contains a BUTTON (and not just passive data). Clicking the button should change the value of a custom field for the custom taxonomy.

    Maybe it’s easier to show it with an image (“Issue” is the custom taxonomy; I’m trying to do an issue-based publishing system):
    http://img442.imageshack.us/img442/669/customcol.png

    My initial solution was to duplicate the default edit taxonomy term form, with hidden fields for the data and a visible submit button. But then I realized that this would create a nested form, since the whole taxonomy term table is wrapped in a form called “posts-filter” (and forms can’t be nested).

    If you have any ideas on how to accomplish this custom column with button, it would be highly appreciated!

    Gabor

    Reply
    • ShibaShake says

      January 26, 2012 at 10:04 pm

      Hmmm, how about just expanding the Quick Edit menu? Otherwise, I suppose we could make each button into a submit button (no form, just the button) and then hook into the relevant form function. But that seems a bit messy.

      Reply
  6. Matic says

    April 6, 2011 at 9:21 am

    Hey!

    First of all congratulations on so informative web site. I found a lot of useful stuff here. Thanks!

    I have one question. I am creating a simple catalog of products. Idea is that product has an thumbnail image a description and simple gallery (using media from wp). Products can be sorted in different categories.

    I’ve created custom taxonomy “Categories” for product. The problem I have is how to attach image to each category? So that when I do category list I can do image grid?

    Thank you for your answer in advance,
    Matic

    Reply
    • ShibaShake says

      April 8, 2011 at 6:29 pm

      The Shiba Media Library plugin allows attachment of images to tags. You can look at that and expand it to attach images to categories.

      Reply
  7. Jeff Rose says

    March 27, 2011 at 1:15 pm

    Thanks for this tutorial. Your site has a ton of stuff. It seems like every time I search, your tutorials come up.

    I hacked in a color code for each term in a taxonomy and used your example to display it along side the other details.

    Reply
  8. Binarybit says

    September 5, 2010 at 9:40 pm

    Could you please either create a post or explain to all of us how on gods earth it is possible to add a custom input field to a taxonomy… this is something which is driving me absolutely crazy!!!

    Reply
    • ShibaShake says

      September 7, 2010 at 7:01 pm

      Yeah, that will be a good article to write. In the meantime, the following two articles contains all the relevant information although not in the most straight-forward fashion –

      How to add meta-data to custom taxonomy objects.
      How to expand the Edit Taxonomy Object interface.

      Reply

Leave a Reply Cancel reply

Your email address will not be published.

Recent Posts

  • Screen-shot of mobile responsive Poll Daddy object, where text floats properly to the right of radio buttons.How to Make Poll Daddy Objects Mobile Responsive
  • Screen-shot of blog post with no page border (flowing design).Genesis Skins 1.5
  • Screen-shot of the media manager Create-Gallery screen, while doing a post search.Shiba Media Library 3.7
  • Screenshot of the Edit Gallery screen after we hit the Create Gallery button.How to Expand the WordPress Media Manager Interface
  • Blonde girl looking through and holding a circular picture frame.Shiba Gallery 4.3
  • Close-up of beautiful blonde holding a square picture frame.Google Authorship - Good or Bad for Search Traffic?
  • Shiba Widgets 2.0
  • Media Temple screenshot of editing my sub-domain DNS entry.Using CDN Cnames with w3tc and MultiSite
  • Shiba Skins WordPress ThemeShiba Skins WordPress Theme
  • How to add the Media Manager Menu to the Theme Preview InterfaceHow to Add the Media Manager Menu to the Theme Preview Interface

Recent Comments

  • WordPress Search Widget – How to Style It (56)
    • Nelson
      - Tanks master - Fine
    • TelFiRE
      - How do you style the "X" that shows up when you start typing?
  • Update custom inputs with the proper data using Javascript.Expand the WordPress Quick Edit Menu (58)
    • Mike G
      - This is exactly what is happening to me. It is updating the value in the database and in the column, but I have to refresh ...
    • PhoenixJP
      - Thanks for this tutorial. Does someone knows if this still work with wordpress 5.03 and 5.1.
    • Francine Carrel
      - This is a very long time away from your original comment, but did you ever work it out? I am stuck on the exact same thing ...
  • Custom meta-box with a set of radio-buttons.Add a Metabox to Your Custom Post Type Screen (27)
    • mike
      - Hi Shiba am a newbie to wordpress, I just installed a plugin with a custom post type, but has no option for discussion and ...
  • Write a Plugin for WordPress Multi-Site (45)
    • Andrew
      - Hi,action 'wpmu_new_blog' has been deprecated. Use ‘wp_insert_site’ instead.
  • Populate our Edit Gallery menu using a gallery shortcode.How to Add the WordPress 3.5 Media Manager Interface – Part 2 (29)
    • Janine
      - Still relevant in 2019.
  • WordPress Excerpt – How to Style It (36)
    • James
      - Great post. I really need some help. I have set border lines around my excerpts on my blog page/post page. The problem is ...
  • Add Custom Taxonomy Tags to Your WordPress Permalinks (123)
    • Darshan Saroya
      - Update permalinks. Go to settings > permalink and just save it.

Copyright © 2021 · Genesis Skins by ShibaShake · Terms of Service · Privacy Policy ·