What is the default archive URL for a Custom Post Type and How can we Modify this archive URL?

When we registers a post type using register_post_type() function, we need to pass two parameters with this function like this : register_post_type( string $post_type, array|string $args = array() ). To get a archive URL for the post type we need to pass ‘has_archive’ to True in $args array.

register_post_type('quick-tips',
    array(
      ....
      'has_archive' => true,
      ....
    )
  );

Then your default archive URL will be like this : https://{your_site_url}/quick-tips/.

Now if you want to modify your default archive URL, we need to pass another argument in $args array like this:

register_post_type('quick-tips',
    array(
      ....
      'has_archive' => true,
      'rewrite' => array(
        'slug' => 'tips-and-trick'
      ),
      .....
    )
  );

Then your quick-tips Custom Post Type archive URL will be like this : https://{your_site_url}/tips-and-trick/.

Leave a Reply

Your email address will not be published.