I'm trying to create a plugin that gives you a push notifications button, through the WordPress editor and I can't find a way to get the permalink of a draft post before its status is set to published.

The predicted permalink already show up in the editor, I just can't find how I can retrieve the same value in my code. get_post_permalink() and get_permalink() don't work until the post is published.

Thx in advance!

  • Maybe you can get post preview link using get_preview_post_link() function to get temporary preview link before the post is published. – dhirenpatel22 Jun 27 '18 at 17:37

You can use get_sample_permalink()

Call get_sample_permalink( $id ) or if you want to pass your own title or slug into it, the full signature is get_sample_permalink( $id, $title = null, $name = null)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.