Is there any way to view your homepage in a preview mode, so that I can check how my posts will look on the homepage before publishing them (i.e. to make sure the featured image looks right etc).

1
1

I think you can set your post to private to view it privately on the homepage.

Once you change the visibility to private, the post or page status
changes to “Privately Published” as shown. Private posts are
automatically published but not visible to anyone but those with the
appropriate permission levels (Editor or Administrator).

See here.


Here is one idea to view draft posts on the site:

Let’s reuse the preview parameter to add the draft posts to the current page view, for example:

- example.com/?preview=true
- example.com/2014/01/?preview=true

We then modify all frontend queries, for logged in users, with:

add_filter( 'posts_where', function( $where ){
   if( ! is_admin() 
       && is_user_logged_in() 
       && 'true' === get_query_var( 'preview' ) 
       && ! is_singular() )
   {
        global $wpdb;
        $from = sprintf( "%s.post_status="publish"", $wpdb->posts ) ;
        if( current_user_can( 'edit_others_posts' ) )
        {
            // add drafts from all users:
            $to = sprintf( "%s.post_status IN ( 'publish', 'draft' ) ", $wpdb->posts ) ;
        }
        else
        {
            // add drafts from current user:
            $sql = " ( %s.post_status="publish" 
                       OR ( %s.post_status="draft"  AND %s.post_author = %d ) ) ";
            $to = sprintf( $sql, 
                           $wpdb->posts, 
                           $wpdb->posts, 
                           $wpdb->posts, 
                           get_current_user_id() 
                  );
        }
        $where  = str_ireplace( $from, $to, $where );       
   }
   return $where;
});

but we could use is_main_query() to restrict the modifications to the main query.

ps: this might need some testing or adjustments … but you get the idea 😉

Leave a Reply

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