Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm in multisite where some blogs share the same parent theme for maintenance reasons. All my cpts come from that parent theme, but I would really like that, for one of the blogs, it had an URL mask.

I found this answer very useful to change labels, but I've tried to do the same and assign a different slug to $wp_post_types[$post_type]->rewrite['slug'] and it fails, bringing the whole rewrite array to NULL.

I've also tried .htacces with RewriteRule ^/newslug$ /oldslug [L] but with no success.

Is there a clean way to do this?

share|improve this question
add comment

1 Answer

Make the slug translatable when you register the custom post type:

register_post_type( 
    'post_type_name', 
    array (
        'rewrite' => array (
            'slug' => _x( 'post_type_name', 'URL slug', 'your_text_domain' )
        )
    )
);

Then create a small plugin for the site where you want to change the slug:

add_filter( 'gettext_with_context', 'change_my_slug', 10, 4 );

function change_my_slug( $translation, $text, $context, $domain )
{
    if ( 'URL slug' !== $context or 'post_type_name' !== $text or 'your_text_domain' !== $domain )
        return $translation;

    return 'changed-slug';
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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