Add Snippet To Project
Have you ever wanted to hide the "Post View" and "Post Preview" admin buttons in WordPress? These buttons can clutter the interface and make it more difficult to navigate, especially if you’re a beginner. In this article, we’ll show you how to remove these buttons and simplify your WordPress experience. Whether you want to clean up your own WordPress dashboard or provide a cleaner interface for your clients, this tutorial is for you. Let’s begin!
function wpturbo_hide_post_view_preview_buttons() {
global $current_screen;
if ( $current_screen->post_type == 'post' ) {
echo '<style type="text/css">
#post-preview, #view-post-btn {display:none;}
</style>';
}
}
add_action( 'admin_head-post.php', 'wpturbo_hide_post_view_preview_buttons' );
The above code snippet provides a way to hide the post view and post preview buttons in the WordPress admin dashboard. This can be useful if you want to simplify the experience for users who don't need access to these buttons.
First, we define a function called wpturbo_hide_post_view_preview_buttons()
. Inside this function, we use the global
keyword to access the $current_screen
variable, which contains information about the current screen in the WordPress admin dashboard.
We then check if the current screen is a post type by using the $current_screen->post_type
property. In this case, we check if the post type is post
.
If the current screen is a post type, we use the echo
statement to output a CSS stylesheet with the display
property set to none
for the #post-preview
and #view-post-btn
HTML elements. This effectively hides the post view and post preview buttons from the user interface.
Lastly, we use the add_action
function to hook the wpturbo_hide_post_view_preview_buttons()
function into the admin_head-post.php
action. This ensures that the function is executed whenever the post editing screen is loaded in the WordPress admin dashboard.