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.


Published
Categorized as WordPress

By Chandra Patel

I fell in love with WordPress in 2014 while freelancing as a web developer. I have grown since then to become a Core contributor, Translation contributor for Gujarati, and has contributed to WordPress Meta projects. Over the years, I have developed a love for learning, and hope to learn WordPress ever more “deeply”.

1 comment

Leave a Reply

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

%d bloggers like this: