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

by ShibaShake 14 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.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comments

  1. Alan Martin says

    May 14, 2020 at 1:02 pm

    Hi there!

    First of all, thanks for much for this tutorial as it is describing exactly what I’m looking to do. However, I’m stuck at getting the images to load… was able to add the column, but the images won’t load (placeholders for broken images show instead). I’m thinking I’m very close but just messed up part of the code. Would you be able to point me in the right direct?

    My custom taxonomy name is ‘brands’ and the custom field name/slug I’m trying to include in the columns is ‘logo’.

    Here is the code I modified off your examples.

    // Add to admin_init function
    add_filter(“manage_edit-brands_columns”, ‘brand_columns’);

    function brand_columns($brand_columns) {
    $new_columns = array(
    ‘cb’ => ”,
    ‘name’ => __(‘Name’),
    ‘logo’ => ”,
    ‘description’ => __(‘Description’),
    ‘slug’ => __(‘Slug’),
    ‘posts’ => __(‘Posts’)
    );
    return $new_columns;
    }

    // Add to admin_init function
    add_filter(“manage_brands_custom_column”, ‘manage_brand_columns’, 10, 3);

    function manage_brand_columns($out, $column_name, $brand_id) {
    $brand = get_term($brand_id, ‘brands’);
    switch ($column_name) {
    case ‘logo’:
    // get logo url
    $data = maybe_unserialize($brand->description);
    $out .= “”;
    break;

    default:
    break;
    }
    return $out;
    }

    Thanks again!
    Alan

    Reply
  2. Daniel says

    January 20, 2017 at 3:48 pm

    Works perfectly. Thanks so much for this!

    Reply
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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

Recent Posts

  • Screenshot of an example article in code view of a modified Gutenberg editor.How to Harness the Power of WordPress Gutenberg Blocks and Combine It with Legacy Free-Form Text
  • Screenshot of the Success, WordPress has been installed page.Migrating Your WordPress Website to Amazon EC2 (AWS)
  • Screenshot of WinSCP for creating a SFTP configuration.How to Set-Up SFTP on Amazon EC2 (AWS)
  • WordPress Gutenberg code view screenshot of this article.How to Prevent Gutenberg Autop from Messing Up Your Code, Shortcodes, and Scripts
  • Screenshot of the Success, WordPress has been installed page.How to Create a WordPress Website on Amazon EC2 (AWS)

Recent Comments

  • Screenshot of an example article in code view of a modified Gutenberg editor.How to Harness the Power of WordPress Gutenberg Blocks and Combine It with Legacy Free-Form Text (1)
    • tom
      - hi,my experience was like the same, but for me as theme developer the "lazy blocks"(https://wordpress.org/plugins/lazy-blocks/) ...
  • WordPress Custom Taxonomy Input Panels (106)
    • Phil T
      - This is unnecessarily confusing. Why declare a variable with the same name as your taxonomy? Why did you choose a taxonomy ...
  • Create Pop-up Windows in Your WordPress Blog with Thickbox (57)
    • Jim Camomile
      - I have used this tutorial several times and it is one of the few simple and effective ways to add popups with dynamic content, ...
  • How to Add Admin Columns in WordPress (7)
    • Andy Globe
      - Hi Friends, I am facing two problem in WordPress admin1. Load custom CSS for wp-admin on user-role base (editor) 2. ...
  • Example blog front-page using excerpts and the Shiba Theme.Optimize Your WordPress Plugins with Tags (5)
    • DF
      - thanks, i went the other way and added a filter if pages I wanted.

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