Last active
February 23, 2018 10:56
-
-
Save mrbobbybryant/79ef228f46de5097802d to your computer and use it in GitHub Desktop.
Introduction to WordPress Filters
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
<?php | |
// Define our Custom Post Type | |
function dwwp_register_post_type() { | |
//Add a filter to our $singular variable. | |
$singular = apply_filters( 'dwwp_label_single', 'Book' ); | |
//Add a filter to our $plural variable. | |
$plural = apply_filters( 'dwwp_label_plural', 'Books' ); | |
$labels = array( | |
'name' => $plural, | |
'singular_name' => $singular, | |
'add_new' => 'Add New', | |
'add_new_item' => 'Add New ' . $singular, | |
'edit' => 'Edit', | |
'edit_item' => 'Edit ' . $singular, | |
'new_item' => 'New ' . $singular, | |
'view' => 'View ' . $singular, | |
'view_item' => 'View ' . $singular, | |
'search_term' => 'Search ' . $plural, | |
'parent' => 'Parent ' . $singular, | |
'not_found' => 'No ' . $plural .' found', | |
'not_found_in_trash' => 'No ' . $plural .' in Trash' | |
); | |
//Add a filter to our cpt's $args variable. | |
$args = apply_filters( 'dwwp_post_type_args',array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_icon' => 'dashicons-businessman', | |
'query_var' => true, | |
'rewrite' => array( 'slug' => $plural ), | |
'capability_type' => 'post', | |
'has_archive' => true, | |
'hierarchical' => false, | |
'menu_position' => 10, | |
'supports' => array( 'title', 'editor', 'author', 'custom-fields' ) | |
) ); | |
register_post_type( $singular, $args ); | |
} | |
add_action( 'init', 'dwwp_register_post_type' ); | |
//Code to be placed on the theme's functions.php file. This code will modify the CPT icon. | |
function dwwp_alter_books_icon( $args ) { | |
$args['menu_icon'] = 'dashicons-book-alt'; | |
return $args; | |
} | |
add_filter( 'dwwp_post_type_args', 'dwwp_alter_books_icon' ); | |
//Code to be placed on the theme's functions.php file. This code will modify the CPT's plural name. | |
function dwwp_cpt_plural( $plural ) { | |
$plural = 'Bookz'; | |
return $plural; | |
} | |
add_filter ( 'dwwp_label_plural', 'dwwp_cpt_plural' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thanks for uploading your file.