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 )

$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.

1 Answer 1


with your code you completely redefine your CPT instead of just modifying the slug maybe this change the public access

try this :

$args = get_post_type_object("portfolio");
$args->rewrite["slug"] = "homepage";
register_post_type($args->name, $args);
  • I tried adding that to both functions and still got a 404 :(
    – Heather
    Commented Jun 29, 2015 at 6:11
  • 1
    have you flush the rewrite rules before to test ? just go to the permalink admin page and save
    – mmm
    Commented Jun 29, 2015 at 6:13
  • 1
    That worked! Added flush_rewrite_rules(); before my second function. Quick question. If I plan to do this several times will I need to flush the rewrite rules every time?
    – Heather
    Commented Jun 29, 2015 at 6:15
  • you need to flush everytime you modify the rules in order to put the new rules in WP cache. but it take long time to flush so don't make it at every page load
    – mmm
    Commented Jun 29, 2015 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.