WordPress.org

Ready to get started?Download WordPress

Forums

Change Custom Post Type Slug, then REDIRECT (4 posts)

  1. aderojas
    Member
    Posted 1 year ago #

    Hello there,

    We have been looking into this for a while but haven't found a good resource, hence here is our question:

    1) We are planning to change the slug of a Custom Post Type, so instead of http://sitename.com/customtypename/post-name we get http://sitename.com/new-customtypename/post-name.

    2) The problem is that we don't want to lose all the traffic coming from external links, and we are looking for the best way to handle the redirection. We rather not to use a pluging for this. Would mod_rewrite on the .htaccess file the way to go? Should we change anything on the databases -other than flushing the permalinks trough the WP dashboard?

    Thanks.

  2. Dhanukanuwan
    Member
    Posted 1 year ago #

    Hi aderojas,

    use 'rewrite' => array('slug' => 'your-slug-here'),

    here is an example

    register_post_type(
    		'portfolio',
    		array(
    			'labels' => array(
    				'name' => 'Packages',
    				'singular_name' => 'Package'
    			),
    			'public' => true,
    			'has_archive' => true,
    			'rewrite' => array('slug' => 'package-type'),
    			'supports' => array('title', 'editor', 'excerpt', 'thumbnail','comments'),
    			'can_export' => true,
    		)
    	);

    remember to refresh the permalink settings.

  3. aderojas
    Member
    Posted 1 year ago #

    Thanks Dhanukanuwan!

    We discovered we had something else going on with the redirections so we are going to wait to change it until we redesign the site, but this definitely helps!

  4. Dhanukanuwan
    Member
    Posted 1 year ago #

    You are welcome :)

Topic Closed

This topic has been closed to new replies.

About this Topic