raja
raja

Reputation: 45

How to Disable Page Revisions in WordPress?

How can I remove Page Revisions in WordPress?

My goal is to reduce the database size.

I am using the code below, but page revisions are still enabled.

define ('WP_PAGE_Revisions', false);

Upvotes: 0

Views: 1512

Answers (5)

BIENVENUE SUR MARS
BIENVENUE SUR MARS

Reputation: 1

TRY : add_filter('wp_page_revisions_to_keep','__return_zero'); add_filter('wp_post_revisions_to_keep','__return_zero');

add_filter('wp_page_revisions_to_keep','__return_zero'); add_filter('wp_post_revisions_to_keep','__return_zero');

The code you've provided is related to WordPress filters that control the number of post revisions to keep in the WordPress database. When you add these filters in your theme's functions.php file or in a custom plugin, it affects how many revisions of a post or page are stored in the database.

The filters you've added, wp_page_revisions_to_keep and wp_post_revisions_to_keep, are using the __return_zero function as their callback. In WordPress, the __return_zero function is a simple utility function that returns the value 0. In the context of these filters, returning 0 means that no revisions will be kept for pages and posts.

Here's a breakdown of what each line does:

add_filter('wp_page_revisions_to_keep','__return_zero');: This line adds a filter to control the number of revisions to keep for pages. By returning 0, you're essentially telling WordPress not to keep any revisions for pages. add_filter('wp_post_revisions_to_keep','__return_zero');: This line adds a filter to control the number of revisions to keep for posts. Again, by returning 0, you're instructing WordPress to not keep any revisions for posts. By setting both of these filters to return zero, you are effectively disabling the storage of revisions for both pages and posts. This can help reduce the size of your WordPress database over time, especially if you have a site with a lot of content and frequent updates.

However, it's important to note that disabling revisions completely might impact your ability to revert to previous versions of content in case of mistakes or accidental changes. It's a trade-off between reducing database size and maintaining a history of content changes. If you decide to disable revisions, make sure you have other backup and versioning mechanisms in place to safeguard your content.

Upvotes: 0

kuhnbn ubstahl
kuhnbn ubstahl

Reputation: 1

I just tried define('WP_PAGE_REVISIONS', 50); It removed all page revisions older than the latest 50 revisions.

Be wary that define('WP_POST_REVISIONS', 50); will only limit the number of revisions for posts, not pages. For limiting the number of page revisions, use the above code. To disable revisions alltogether, replace the number by false

Upvotes: 0

Another use case is If you’re like most people, you’ll want to have a couple of post revisions for each post you add to your blog – just err on the safe side. The best way to accomplish this is to set a hard limit on the # of post revisions that are saved to the wordpress DB. You can try adding the following code (1 line) to your wp-config.php

define( ‘WP_POST_REVISIONS’, 3 ); 

What this line of code will accomplish is that it will save the 3 most recent post revisions instead all of the revisions and it will automatically delete as newer revisions occur.

Of course feel free to replace (3) with your ideal number of post revisions you would like to keep

Upvotes: 1

mburesh
mburesh

Reputation: 1028

Setting WP_Page_Revisions to false will only stop WordPress from storing future revisions. If you want to remove existing revisions, you'll have to go into your database and delete them or use a plugin like this one to handle it.

Upvotes: 0

Deepak Kedia
Deepak Kedia

Reputation: 174

define( 'WP_POST_REVISIONS', 0 );

Try this.

Hope this helps.

Upvotes: 1

Related Questions