I successfully renamed a custom post type registered by my parent theme in my child theme using this method. The problem is, my permalinks haven't changed. So when I change portfolio
to homepage
and use the permalink structure /%category%/%postname%/
my URLs still look like mysite.com/portfolio/page/ instead of mysite.com/homepage/page/.
this is the code I am using to change my CPT:
add_action( 'wp_loaded', 'wpse_19240_change_home_labels', 20 );
function wpse_19240_change_home_labels()
{
global $wp_post_types;
$b = 'portfolio';
if ( empty ( $wp_post_types[ $b ] )
or ! is_object( $wp_post_types[ $b ] )
or empty ( $wp_post_types[ $b ]->labels )
)
return;
$wp_post_types[ $b ]->labels->name = 'Sliders';
$wp_post_types[ $b ]->labels->singular_name = 'Slider';
$wp_post_types[ $b ]->labels->add_new_item = 'Add New Slider';
$wp_post_types[ $b ]->labels->edit_item = 'Edit Slider';
$wp_post_types[ $b ]->labels->new_item = 'New Slider';
$wp_post_types[ $b ]->labels->view_item = 'View Slider';
$wp_post_types[ $b ]->labels->search_items = 'Search Sliders';
$wp_post_types[ $b ]->labels->not_found = 'No sliders found.';
$wp_post_types[ $b ]->labels->not_found_in_trash = 'No sliders found in Trash.';
$wp_post_types[ $b ]->labels->menu_name = 'Homepage Sliders';
$wp_post_types[ $b ]->labels->all_items = 'All Sliders';
$wp_post_types[ $b ]->labels->add_new = 'Add New Slider';
$wp_post_types[ $b ]->labels->name_admin_bar = 'Slider';
}
I sucessfully changed the slug by using:
function change_slug_of_post_type_portfolio() {
register_post_type('portfolio', array('rewrite' => array ('slug' => 'homepage',)));
}
add_action('init', 'change_slug_of_post_type_portfolio', 20);
But now I get a 404 error when I navigate to the page generated by the system: mysite.com/homepage/page/
I made sure to make a single-homepage.php and I have tried adding flush_rewrite_rules();
as recommended in this post but to no avail.