Last active
January 18, 2016 12:03
-
-
Save jfitzsimmons2/7723147 to your computer and use it in GitHub Desktop.
A Sublime Text snippet that expands into a function that will register a custom post type in WordPress. CPT + Tab will generate the code.$1 = lowercase forms of the CPT name$2 = uppercase forms of the CPT name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
<?php | |
add_action( 'init', 'register_cpt_$1' ); | |
function register_cpt_$1() { | |
$labels = array( | |
'name' => _x( '$2s', '$1' ), | |
'singular_name' => _x( '$2', '$1' ), | |
'add_new' => _x( 'Add New $2', '$1' ), | |
'add_new_item' => _x( 'Add New $2', '$1' ), | |
'edit_item' => _x( 'Edit $2', '$1' ), | |
'new_item' => _x( 'New $2', '$1' ), | |
'view_item' => _x( 'View $2', '$1' ), | |
'search_items' => _x( 'Search $2s', '$1' ), | |
'not_found' => _x( 'No $1s found', '$1' ), | |
'not_found_in_trash' => _x( 'No $1s found in Trash', '$1' ), | |
'parent_item_colon' => _x( 'Parent $2:', '$1' ), | |
'menu_name' => _x( '$2s', '$1' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'description' => '', | |
'supports' => array( 'title', 'editor', 'thumbnail' ), | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'publicly_queryable' => true, | |
'exclude_from_search' => false, | |
'has_archive' => true, | |
'query_var' => true, | |
'can_export' => true, | |
'rewrite' => true, | |
'capability_type' => 'post' | |
); | |
register_post_type( '$1', $args ); | |
} | |
?> | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<tabTrigger>CPT</tabTrigger> | |
<!-- Optional: Set a scope to limit where the snippet will trigger --> | |
<!-- <scope>source.python</scope> --> | |
</snippet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is fantastic -- only minor point is you need to escape the $args and $labels with a \
\$args = array(
\$labels = array(
Otherwise they are not pulled when you trigger it