186 PART III • Using Plugins with WordPress
Figure 7-3: The Smashing Tags taxonomy.
Not too complicated, right? You can use this code in functions.php, but chances are your
taxonomy really isn’t theme-related but rather something that belongs with the content, and
that means a plugin is more portable. Just putting the code within PHP tags and adding the
plugin header will do the trick, so here’s the Smashing Taxonomy plugin file:
<?php
/*
Plugin Name: Smashing Taxonomy
Plugin URI: http://tdh.me/wordpress/smashing-taxonomy/
Description: Adding the Smashing Tags taxonomy.
Version: 1.0
Author: Thord Daniel Hedengren
Author URI: http://tdh.me/
*/
// Attach function to init hook
add_action( 'init', 'smashing_tax', 0 );
// Taxonomy function
function smashing_tax() {
// Register the taxonomy
register_taxonomy( 'smashing_taxonomy', 'post',
array(
'hierarchical' => false,
'labels' => array(
'name' => 'Smashing Tags',
'singular_name' => 'Smashing Tags',
'search_items' => 'Search Smashing Tags',
'popular_items' => 'Popular Smashing Tags',
'add_new_item' => 'Add New Smashing Tags'
),