The best way to do that is with this plugin:
https://wordpress.org/plugins/public-post-preview/
OF course you can dig into it’s source code to try to implement the core functionality if you prefer, but I use that plugin on several active sites with success.
Related Posts:
- Where is the old post permalink slug stored?
- How to automatically generate a unique random slug
- Change permalinks for post type ‘post’ only
- Why can posts never have a number as the link?
- Setting post meta data to random value during post status transition / on publish
- How to change post status from publish to draft using hook in wordpress?
- How to allow slashes in single posts when i click in the edit permalink button
- Hiding by default specific post status on backend list?
- Some posts returning 404 instead of displaying post
- Link for the page archive for posts, like using custom post types with get_post_type_archive_link
- Custom Post Status Posts viewable to the public
- Random post permalink
- get_permalink executes link without https
- Custom post type permalinks breaking due to 3.1 bug fix
- Create pretty permalink for a post knowing the permalink structure
- Changing my permalink structure – will new layout conflict with existing page?
- Link post permalinks to subdirectory /post
- add filter to “quick edit menu” in wordpress admin
- Remove permalink from images when inserting into post
- What differences are there between a Privately Published post and a Draft post?
- Remove the Edit button in posts for permalinks on certain user roles? WP 3.3
- Dynamically generate child-URLs for posts or custom posts
- Update post status from “publish” to “trash” for half of posts
- Adding parent pages to posts
- Plain permalinks not working!
- how to remove dash (-) post status from post title on posts listing page wordpress
- Changing Permalinks for Default Post type to reflect navigation
- How should I add links to other pages/posts from my post?
- Using permalinks, category slugs, and tag slugs
- Problem with permalink routing?
- Move first half of posts to one parent page, second half to the other page
- How to check a post exist when the permalink has post id in it?
- How to do set post permalinks using 6 digit random unique function?
- Trying to use AngularJS with WordPress without any API
- How to handle broken links created by permalink/slug changes?
- Visting slug for ‘post’ post type shows 404 not archive?
- Any way for get_next_post() to use the actual post order instead of publish order?
- how do i add posts-page slug before posts slug in permalinks
- Admin – create custom post status and display above table
- WordPress capabilities on pending post status
- hiding permalink in admin if the user is subscriber
- Why does WP_Post not contain its permalink?
- the_permalink() not working in a root installation
- why there are so many posts whoes post_type is revision? will these records waste too much database space?
- $post->post_type not working
- Second get_permalink inside loop points to wrong URL
- how can i allow users to view their own pending posts in a front-end page
- Custom Permalink Structure for Pages & Posts
- register_post_type permalink
- Post is blank when I click on the link
- Custom permalink for each post
- Is there a way getting post fields using `transition_post_status`
- Post/page title to permalink transformation – what is behind the scenes?
- Post titles and thumbnails as links to custom post types?
- Showing posts for today and future
- Making posts permalinks consistent numbers
- Can Permalink structure of %postname%/%post_id% improve performance
- How to link post titles on page A to its posts on page B?
- Categories Listing and Highlighting current category item
- Changing permalink of WordPress
- Set Default Post as Parent Child (Nested) Relation
- How can I add random alphabets in wordpress permalink posts structure
- Show Last Revision Of Post That Has A Published Status On Single Page
- Remove subcategory slug from url
- Can I show category name in url for only one of my categories?
- How to set a Post’s default visibility to ‘Private’ in Gutenberg?
- Please help a newbie with blog page issue?
- How can I make a post sub link?
- How do you change the permalink for posts for a single category?
- Private post caught in endless redirect loop
- WP posts using index.php instead of single.php
- How to add a ‘News’ section to specific posts in WordPress
- Add a url parameter to the current post and read it in a shortcode
- How publish post from pending status
- Put page on Archived statut after end of publication date
- get_next_post() not working with future post status
- How can I set the permalink of an article / page equal to the permalink of an existing article / page?
- How to add category base prefix to wordpress permalink
- Category URL to use same string as Post URL Permalink
- Permalink base only for posts
- Change the URL of posts by category
- Point users to a specific url directory for some posts
- Precedence of page permalinks over woocommerce product category links?
- Post & Category Archives URL structure
- post_name is not stored until post is published… where should I store my slug until it goes live then?
- Function/filter or plugin to change post status based on custom field value
- One of my posts is displayed as page
- Make assigning post to a specific category equivalent to assigning it to all categories
- Modifying the permalink href for posts with jquery
- After the local installation of an old WP website I can see the homepage but I can’t access to the articles, why?
- Default post type doesn’t display in url
- Do anything on post_status change [duplicate]
- How to change Permalinks only for Blogposts
- Permalink structure for two separate blogs
- How can I fixe the article title problem?
- How to add paraent in Blog post URL in wordpress
- Why can posts never have a number as the link?
- Modify Post URL Programmatically
- editPost without undo entry
- Custom permalink for ‘post’ not working