Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Block WordPress Post Updates and Deletion After a Set Period

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Block WordPress Post Updates and Deletion After a Set Period

Managing WordPress website with multiple authors can be complicated sometimes. There are plugins to manage editorial workflow, but you may come across situations where you need specific solutions for better control of your WordPress site. Recently, we helped a user find such a solution. They wanted to block WordPress post updates and deletion after a set period of time for all users (including editors) after a set period of time. For example, if a published post is 30 days or older, then it cannot be edited or deleted by editors. Only administrators can modify that post. In this article, we will show you how to block post edit, updates, and deletion after a set period of time in WordPress.

Locking posts updates and deletion for older published posts in WordPress

All you need to do is add the following code in your theme’s functions.php file or in a site-specific plugin.

function wpbeginner_restrict_editing( $allcaps, $cap, $args ) {

    // Bail out if we're not asking to edit or delete a post ...
    if( 'edit_post' != $args[0] && 'delete_post' != $args[0]
      // ... or user is admin
      || !empty( $allcaps['manage_options'] )
      // ... or user already cannot edit the post
      || empty( $allcaps['edit_posts'] ) )
        return $allcaps;

    // Load the post data:
    $post = get_post( $args[2] );

    // Bail out if the post isn't published:
    if( 'publish' != $post->post_status )
        return $allcaps;

    //if post is older than 30 days. Change it to meet your needs
    if( strtotime( $post->post_date ) < strtotime( '-30 day' ) ) {
        //Then disallow editing.
        $allcaps[$cap[0]] = FALSE;
    return $allcaps;
add_filter( 'user_has_cap', 'wpbeginner_restrict_editing', 10, 3 );

This function checks if the user has the capability to edit or delete posts. After that it checks for the post status. If a post is published and is older than 30 days, then user’s capability to edit and delete the post is taken away. If a post is published, but it is not older than 30 days, then the users with the ability to edit posts can still edit it. Note: Administrators can edit and delete posts anytime they want.

We hope that this article helped anyone who is looking to block post edit, update and deletion in WordPress after a set period of time. Would you ever do this on your site? What use cases can you see for something like this? Let us know in the comments below.


Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. vivek says:

    how can i make only some post id’s protected from deleting

  2. Zeeshan says:

    Hi, I used your solution and that works fine, but How can I also hide the options of “Edit | Quick Edit | Trash | Duplicate” and show only “View” in such posts, When I click on the Edit or delete it just refreshes the page and doesn’t show any error/warning message that “You are not allowed to edit this post”

    I would like to either have messages when user clicks on Edit or Delete or just remove the options


  3. vahid says:

    Thank you.
    How can we change 30 days to for example 5 days?

  4. Igor says:

    Is it possible with this function to move publised post to draft after 30 days? Can you help please?

  5. Ajit says:

    Really nice and helpful trick

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.