Aljon Ngo
Aljon Ngo

Reputation: 251

Remove "preview" button in admin "add new post" if not yet submitted wordpress

I want to remove the preview button if the post is not yet submitted or saved. When you click the preview button while the post is noy yet submitted at the publish section it will redirect you to a 404 page.

where to edit the codes so that i can make the button preview hidden if the post is not yet submitted for preview and show if it is already saved.

enter image description here

Upvotes: 1

Views: 2648

Answers (1)

Aljon Ngo
Aljon Ngo

Reputation: 251

I already created an simple solution to this problem

//hide preview button if not yet saved as draft
if(!isset($_GET['post'] )){
    add_action('admin_head', 'hidePreviewButtonSaAdmin');
    function hidePreviewButtonSaAdmin() {
      echo '<style>
            #post-preview{
                display:none !important;
            }               
            } 
          </style>';
    }
}

initially the post does not have "post" parameter in the url. When we saved it as a draft, an id for the post will be generated. We can now use the id of the post for our "if" statement.

note that i paste this code in my function.php of my theme.

Upvotes: 3

Related Questions