What is the default archive URL for a Custom Post Type and how can we modify that archive URL?

When we register 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 an archive URL for the post type, we need to pass ‘has_archive’ to True in the $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 the $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. Required fields are marked *