The Trash Button widget enables users to delete existing posts from the frontend of a WordPress website, without needing to interact with the WordPress dashboard.
Important: By default a user needs to be logged in and carry the “administrator” role to use the button and be able to delete posts. This can be changed, however, in the Permissions settings of this widget.
By adding the widget to a Single Post Template in Elementor we are able to have it appear automatically on all posts. This will display a button to allow your users to delete the post currently being viewed.
Please note that custom templates are built using the Elementor Theme Builder, which is only available in Elementor Pro.
Adding the Widget
If you don’t already have a template for your posts, you need to create one. To create a new template click Add New under Templates in the WordPress dashboard. Choose Single Post to create a template for your posts.
You can choose to insert an existing template to edit or start from scratch. You can learn more about templates in Elementor’s official tutorial.
Navigate to the template’s edit page by clicking Edit with Elementor, and drag in the Trash Button Widget. This can be found in the Frontend Forms section or by searching for the “Trash Button” widget.
The style of the button itself can be customized. You can change the text shown and add a custom icon. You can also customize the confirmation message.
Here you also configure where the user will be redirected to after the delete action is completed. A common choice is to redirect them to the user dashboard.
Note that if you choose Reload Current URL it will reload the page of the now deleted post, and reach a 404 error.
This is where we limit which kinds of users will be able to see the button. It is very important to configure this correctly, as otherwise your users might not be able to see the button at all!
By default, only administrators can see the button. If you want to allow other users to access it, you need to add them. There are several ways to do that.
First, you can specify whether or not users need to be logged in to view the button, under the Who Can See This… option.
You can allow certain Roles to access the button under the Select By Role option. This allows you to add all Editors, for example.
You can also add specific users under the Select By User option. The users selected here will always be able to see the button.
If you would like the author of the post to be able to delete his/her post, you will need to add that under the Dynamic Permissions option.
Saving the Template
When you finish designing the button, you will need to save the template. By limiting the template to specific pages or post types you can ensure the delete button is only shown on those types of posts or pages.
If you want the delete button to appear on all posts then choose Include -> Posts -> All as the condition.
To see the conditions of a given template click the arrow next the the “Update” button and then click Display Conditions. To learn more about Display Conditions, see the official Elementor tutorial here.
Here you can see the Trash Button widget in action.