Chandra Patel

Just Another Developer

How to get sample permalink

My colleague was working on an issue where we needed a permalink of the draft post. So he used get_permalink() function to get post permalink. However the get_permalink() returns URL something like https://example.com?p=6 and we needed full permalink something like https://example.com/post-slug/

The get_permalink() function returns full permalink for the published post only. He explored WordPress codebase and he found get_sample_permalink() which returns an array containing the sample permalink with a placeholder for the post name, and the post name.


One response to “How to get sample permalink”

  1. Imran Sayed Avatar

    Useful information.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.