It’s surely too early in the New Year for WordPress to be causing grief? Apparently not 🙂

We just had a simple request from a client, “Can we change the URLs for our custom post type pages” – no problem I thought!

However, this one has taken me longer than expected. It should have been a simple case of changing the Slug parameter when registering a custom post type.

So:

[php]
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘menu_icon’ => get_template_directory_uri() . ‘/images/iconbacourse.png’,
‘rewrite’ => array(‘slug’ => ‘old-slug’),
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’thumbnail’)
);

register_post_type( ‘myposttype’ , $args );
[/php]

Becomes:

[php]
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘menu_icon’ => get_template_directory_uri() . ‘/images/iconbacourse.png’,
‘rewrite’ => array(‘slug’ => ‘new-slug’),
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => null,
‘supports’ => array(‘title’,’editor’,’thumbnail’)
);

register_post_type( ‘myposttype’ , $args );
[/php]

This should mean posts that were at /old-slug/page-name are now at /new-slug/page-name

Doing this, meant the old Urls were redirecting to the correct location, but I was getting a 404! The solution was upsettingly simple, go in to WP Admin, Settings, Permalinks and re-save your permalink structure.

Hope this might help someone, and happy WordPressing in 2012 😉

Related Stories