Managing content on your WordPress site is important. Sometimes, you need to remove old content. You may also want to hide a part of a post after some time. This article will show you how to do that.

Credit: www.wpbeginner.com
Why Expire Posts or Content?
Expired content can confuse readers. It can also affect your site’s performance. By expiring posts or parts of posts, you keep your site fresh. This helps with better user experience and SEO.
Methods to Expire Posts
There are different ways to expire posts in WordPress. Here are some common methods:
- Using a plugin
- Editing the post’s publish date
- Using custom code
Using A Plugin
Plugins make it easy to manage content. Here are some popular plugins:
Plugin Name | Description |
---|---|
Post Expirator | Automatically expires posts after a set time. |
Content Scheduler | Helps schedule and expire posts. |
How to Use Post Expirator
- Go to your WordPress dashboard.
- Click on Plugins and then Add New.
- Search for Post Expirator.
- Click Install Now and then Activate.
- Edit a post you want to expire.
- Find the Post Expirator box.
- Set the date and time for the post to expire.
- Choose what happens to the post after expiry (e.g., move to draft).
- Click Update to save changes.
Editing The Post’s Publish Date
This method is simple. It does not require a plugin. Here is how to do it:
- Go to your WordPress dashboard.
- Click on Posts.
- Select the post you want to expire.
- Click on Edit.
- Find the Publish box on the right.
- Click on the Edit link next to the Publish immediately option.
- Set a date in the past.
- Click on OK.
- Click on Update to save changes.
Using Custom Code
This method is for advanced users. You need to add custom code to your theme’s functions.php file. Here is an example:
function expire_post() {
$args = array(
'post_type' => 'post',
'meta_query' => array(
array(
'key' => 'expire_date',
'value' => current_time('mysql'),
'compare' => '<=',
'type' => 'DATETIME'
)
)
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
wp_update_post(array(
'ID' => get_the_ID(),
'post_status' => 'draft'
));
}
}
}
add_action('wp', 'expire_post');
Add this code to your theme’s functions.php file. Then, add a custom field named expire_date to your posts. Set the value to the expiry date.
Methods to Expire Partial Post Content
Sometimes, you want to hide only part of a post. Here are some methods to do that:
- Using a plugin
- Using shortcodes
- Using custom code
Using A Plugin
Plugins can help hide parts of a post. Here are some popular plugins:
Plugin Name | Description |
---|---|
WP ShowHide | Hides content with a shortcode. |
Content Visibility | Controls visibility of content parts. |
How to Use WP ShowHide
- Go to your WordPress dashboard.
- Click on Plugins and then Add New.
- Search for WP ShowHide.
- Click Install Now and then Activate.
- Edit a post you want to hide part of.
- Wrap the content you want to hide with the [showhide] shortcode.
- Click Update to save changes.
Using Shortcodes
You can create custom shortcodes to hide content. Here is an example:
function hide_content_shortcode($atts, $content = null) {
$expiration_date = $atts['date'];
if (current_time('mysql') < $expiration_date) {
return $content;
} else {
return 'Content expired.';
}
}
add_shortcode('expire_content', 'hide_content_shortcode');
Add this code to your theme’s functions.php file. Then, use the shortcode in your posts:
[expire_content date="2023-12-31 23:59:59"]This content will expire on December 31, 2023.[/expire_content]
Using Custom Code
This method is for advanced users. You need to add custom code to your theme’s functions.php file. Here is an example:
function expire_partial_content($content) {
$expire_date = get_post_meta(get_the_ID(), 'expire_date', true);
if (current_time('mysql') > $expire_date) {
$content = 'Content expired.';
}
return $content;
}
add_filter('the_content', 'expire_partial_content');
Add this code to your theme’s functions.php file. Then, add a custom field named expire_date to your posts. Set the value to the expiry date.

Credit: passwordprotectwp.com
Frequently Asked Questions
How Can I Set Expiration Dates For WordPress Posts?
Use plugins like Post Expirator to set expiration dates for posts.
Can I Expire Only Part Of A Post In WordPress?
Yes, plugins allow you to expire specific content within a post.
Which Plugin Is Best For Expiring WordPress Posts?
Post Expirator is a popular plugin for expiring posts.
Is It Possible To Schedule Content Expiration?
Yes, you can schedule content expiration with specific plugins.
Conclusion
Expiring posts or parts of posts helps manage your content. It keeps your site fresh and user-friendly. You can use plugins, shortcodes, or custom code. Choose the method that works best for you. Keep your content up-to-date for a better user experience.