Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm registering 7 custom taxonomies in my functions.php. Since each function uses the same labels and arguments and is attached to the same Custom Post Type, I'm wondering if it's possible to register all the taxonomies in 1 function? Here is the code that is repeated 7 times with the <XXX> as the only changing parts:

function custom_taxonomy_<XXX> ()  {
$labels = array(
    'name'                       => '<XXX>',
    'singular_name'              => '<XXX>',
    'menu_name'                  => '<XXX>s',
    'all_items'                  => 'All <XXX>s',
    'parent_item'                => 'Parent <XXX>',
    'parent_item_colon'          => 'Parent <XXX>:',
    'new_item_name'              => 'New <XXX> Name',
    'add_new_item'               => 'Add New <XXX>',
    'edit_item'                  => 'Edit <XXX>',
    'update_item'                => 'Update <XXX>',
    'separate_items_with_commas' => 'Separate <XXX> with commas',
    'search_items'               => 'Search <XXX>s',
    'add_or_remove_items'        => 'Add or Remove <XXX>s',
    'choose_from_most_used'      => 'Choose from the most used <XXX>s',
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => true,
    'query_var'                  => true,                       
);
register_taxonomy( '<XXX>', 'custom_post_type', $args );
}
add_action( 'init', 'custom_taxonomy_<XXX>', 0 );           
share|improve this question
add comment

1 Answer 1

Nope. Not the WordPress way at least.

You could probably make helper function (plain PHP realm in other words) to build instances of label arrays, however that would seriously hinder making strings translatable.

share|improve this answer
    
Thank you, Rarst. I was thinking of something along those lines. I do not need the strings to be translatable (to other languages, if that is what you mean). Can you point me in the direction of that type of helper function code? –  codeview Oct 23 '13 at 16:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.