Example 1 — Get a custom post type URL
Imagine a book custom post type with pretty permalinks.
<?php
echo esc_url( get_post_permalink( 12 ) ); How It Works
- Post 12 is a
book. - The function builds the link from the book rewrite rules.
esc_url()keeps the output safe.

