Skip to main content
We are Brand SEO Beijing serving international business, your marketing partner, Contact us by mi@mgsh.com.cn

How to save versions of website articles for restoring historical content?

By modifying the configuration to realize the multi-version preservation of the article, it is used for the backup and recovery of the article content, so as to avoid accidental error modification, which is to improve the security and friendliness of the website system.If the website does not have this function, we need to optimize our behaviors to avoid operational losses. With this function, we have an extra insurance.
By learning how to modify the article version function of Wordpress, we can learn the framework of the content management system, and the thinking habits behind each function, field, configuration, configuration method, configuration logic, and system node intercommunication. It has to be said that the West is at the bottom and We are far ahead of us in long-term thinking, but if we can recognize it, we believe that growth is still very fast. After all, we cannot grow because we cannot see or turn a blind eye.
Here are two effective ways to disable auto-save, auto-draft, and revisions in WordPress.

Disable feature by modifying WordPress configuration file

WordPress has a sequential logic, which one is called first, which one is called later, which is public, which is private, which plays the role of the global domain, and which plays the role of the private domain. Install the wp-config.php configuration file in the root directory to enable the function. Disabled is global, I think.

//Disable auto save define('AUTOSAVE_INTERVAL', false); //Set auto save interval/seconds define('AUTOSAVE_INTERVAL', 120); //Disable article revisions define('WP_POST_REVISIONS', false); //Set revisions Up to several define('WP_POST_REVISIONS', 3);

Add code using current theme functions.php file

Disable WordPress Autosave

//Disable autosave (method XNUMX) add_action( 'admin_print_scripts', create_function( '$a', "wp_deregister_script('autosave');" ) );
//Disable autosave (method XNUMX) add_action('wp_print_scripts', 'mgsh_no_autosave'); function mgsh_no_autosave() { wp_deregister_script('autosave'); }

You can check the action list of WP, so you can find out admin_print_scripts, wp_print_scripts and wp_deregister_script('autosave').
Prompt, the above are two kinds of banned WordPress Auto savemethod, please note before editing long articlesManual save; It is not recommended to turn off automatic saving, and the disk space is still sufficient.

Disable WordPress revisions

//Disable revisions for all post types add_filter( 'wp_revisions_to_keep', 'mgsh_wp_revisions_to_keep', 10, 2 ); function mgsh_wp_revisions_to_keep( $num, $post ) { return 0;}
//Disable revisions for a certain post type add_filter( 'wp_revisions_to_keep', 'mgsh_wp_revisions_to_keep', 10, 2 ); function mgsh_wp_revisions_to_keep( $num, $post ) { if ( 'post_type' == $post->post_type ) { / / Change post_type in quotes to the post type you want to disable revisions for return 0; } return $num; }

Common WordPress default article types are:

  • Post (Post Type: 'post')
  • Page (Post Type: 'page')
  • Attachment Media (Post Type: 'attachment')
  • Revision (Post Type: 'revision')
  • Navigation menu (Post Type: 'nav_menu_item')

Of course, if the website uses a custom post type, then it is a custom name.
When I have time, I will write down the logic.

Back to Top