Skip to content

Instantly share code, notes, and snippets.

@mannieschumpert
Last active October 11, 2015 06:18
Show Gist options
  • Save mannieschumpert/3815767 to your computer and use it in GitHub Desktop.
Save mannieschumpert/3815767 to your computer and use it in GitHub Desktop.
WordPress Taxonomy Snippet for Sublime Text
<snippet>
<content><![CDATA[
// Create taxonomy
add_action( 'init', 'create_${1:FUNCTION}' );
function create_${1:FUNCTION}() {
\$labels = array(
'name' => _x( '${3:PLURAL}', 'taxonomy general name' ),
'singular_name' => _x( '${2:SINGULAR}', 'taxonomy singular name' ),
'search_items' => __( 'Search ${3:PLURAL}' ),
'all_items' => __( 'All ${3:PLURAL}' ),
'parent_item' => __( 'Parent ${2:SINGULAR}' ),
'parent_item_colon' => __( 'Parent ${2:SINGULAR}:' ),
'edit_item' => __( 'Edit ${2:SINGULAR}' ),
'update_item' => __( 'Update ${2:SINGULAR}' ),
'add_new_item' => __( 'Add New ${2:SINGULAR}' ),
'new_item_name' => __( 'New ${2:SINGULAR} Name' ),
);
register_taxonomy('${3:PLURAL}','${4:POST-TYPE}',array(
'hierarchical' => true, // false for tags
'labels' => \$labels
));
}
]]></content>
<tabTrigger>wptax</tabTrigger>
<scope>source.php</scope>
</snippet>
@mannieschumpert
Copy link
Author

Usage

  1. Type `wptax' (or just start typing it) Hit Tab. The block above will be inserted.
  2. The two FUNCTION instances will be selected. Enter your desired function suffix.
  3. Tab. The SINGULAR instances will be selected. Enter the singular version of your taxonomy name.
  4. Tab. The PLURAL instances will be selected. You know what to do.
  5. Tab. Enter the Post Type that the taxonomy will be associated with.

@cobblucas
Copy link

This is very useful Mannie - Thanks for the share!

@mannieschumpert
Copy link
Author

I just fixed something that's bugged me for a while: the $labels needed to be escaped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment