wordpress change custom post type name code example
Example 1: get name custom post type wordpress
$pt = get_post_type_object( 'books' );
// These two usually contain the post type name in plural.
// They may differ though.
echo $pt->label;
echo $pt->labels->name;
// This one holds the post type name in singular.
echo $pt->labels->singular_name;
Example 2: wordpress change custom post type slug
function add_custom_rewrite_rule() {
// First, try to load up the rewrite rules. We do this just in case
// the default permalink structure is being used.
if( ($current_rules = get_option('rewrite_rules')) ) {
// Next, iterate through each custom rule adding a new rule
// that replaces 'movies' with 'films' and give it a higher
// priority than the existing rule.
foreach($current_rules as $key => $val) {
if(strpos($key, 'movies') !== false) {
add_rewrite_rule(str_ireplace('movies', 'films', $key), $val, 'top');
} // end if
} // end foreach
} // end if/else
// ...and we flush the rules
flush_rewrite_rules();
} // end add_custom_rewrite_rule
add_action('init', 'add_custom_rewrite_rule');