WordPress get_post_type_archive_link Example: Link CPT Archives Safely
Retrieve custom post type archive links safely with get_post_type_archive_link() instead of hardcoding slugs or guessing archive URLs.
Published
May 2, 2026
Reading Time
2 min read
Updated
May 3, 2026

Implementation Notes
Extension points, code paths, and implementation choices that should survive contact with production.
Best For
WordPress developers, agencies, and technical teams building custom plugin or theme functionality with cleaner operational defaults.
Primary Topics
Editorial Focus
Build Pattern: Extension points, code paths, and implementation choices that should survive contact with production. Updated on May 3, 2026.
Full Report
Last reviewed: May 3, 2026
Custom post type archives need reliable “view all” navigation, but many themes still hardcode slugs instead of asking WordPress for the actual archive permalink. get_post_type_archive_link() is the core helper for generating that link safely.
This guide shows how to retrieve a custom post type archive link and handle the cases where the archive does not exist.
Retrieve the archive link explicitly
<?php
$archive_url = get_post_type_archive_link( 'case_study' );
if ( $archive_url ) {
echo '<a href=\"' . esc_url( $archive_url ) . '\">All Case Studies</a>';
}
The conditional matters because the helper returns false if the post type does not exist or is not registered with an archive.
The archive has to be enabled in the registration
The WordPress reference makes this explicit: a post type without has_archive has no archive permalink to retrieve. Theme code should not assume every custom post type exposes an index page.
Do not hardcode the archive slug in templates
Archive slugs can change with registration updates. Using the helper keeps breadcrumbs, CTAs, and back-links aligned with the real content model.
Remember the built-in post type is a special case
The default post type uses the posts page configuration, which is another reason manual URL construction is brittle.
Production checklist
- Use the helper instead of hardcoded archive URLs.
- Handle the
falsereturn path before rendering links. - Confirm
has_archivein the post type registration. - Retest archive links after permalink or CPT registration changes.
- Use clear archive labels in templates and breadcrumbs.
- Keep navigation aligned with how users actually discover the content.
Common mistakes
- Hardcoding archive slugs. Templates drift when the registration changes.
- Ignoring false returns. Not every post type has an archive.
- Treating the built-in post type like a normal CPT. Posts page rules are different.
- Linking to archives for non-public content models. Navigation should reflect visibility.
- Skipping permalink regression testing. Archive routing is easy to break.
Related reading
If the CPT itself still needs archive-ready registration, pair this with the custom post type guide. If the theme must behave differently on the archive request itself, continue with the is_post_type_archive article.


