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.


Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

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

%d bloggers like this: