After using WordPress for so long, I have always hated the article revision and auto-save functions of WordPress. I have also used the super switch plug-in to disable the article revision and auto-save functions of WordPress. However, my blog already has enough plug-ins, so I had to modify WordPress. The main program is used to implement the functions of prohibiting article revision and automatic saving. But the disadvantage of this method is that every time WordPress is upgraded, the WordPress source code must be modified again, which is really troublesome. Today I accidentally bumped into the ZWW blog and found this non-plug-in-free source code method to implement wordpress's prohibition of article revisions and automatic saving. Share it with everyone!
The method of use is very simple, just add the corresponding code to functions.php in the theme directory. The code is as follows:
If you don’t particularly care, even discontinuity is irrelevant, and this article won’t make much sense to you.
1. Disable article revision
The so-called article revision means that every time you modify an article, it will automatically save the article version before modification for you. The professional term is called version control, which ensures that the article is modified by mistake. In some cases, the previous content can be restored. This is very helpful in maintaining Wiki documents, but as our small blog, it does not seem to be of much use. Moreover, this revision occupies an ID in the database, which also causes One of the problems with discontinuous article IDs. To disable article revisions, you can add in the wp-config.php file:
1
define('WP_POST_REVISIONS', false);
2. Delete the article Revisions
After disabling article revisions, the previously created article revisions are still stored in the database. These are actually of little use and occupy the ID. We can delete them. As for how to delete, you can execute the following SQL statement in phpmyadmin (make a backup):
12345
DELETE a,b,cFROM wp_posts aLEFT JOIN wp_term_relationships b ON (a.ID = b. object_id)LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)WHERE a.post_type = 'revision';
3. Delete unnecessary attachments
I believe many bloggers will do this when publishing articles Upload/insert some attachments, such as images, videos, music, etc. These attachments can be seen in the WordPress management background – Media Library. Different media corresponds to different articles. But you should note that these media also occupy the article ID, and they are stored in the same database table wp_posts as the article. If you particularly pursue that the IDs of the articles must be perfectly continuous, please do not upload/insert these media when publishing the article, and please delete the previously uploaded media in the WordPress management background – media library (note that this operation is not just deletion) records, and the files you uploaded will be deleted), please use FTP to re-upload these files if necessary.
4. Disable auto-save
The advantage of auto-save is that when you edit an article, the system will automatically save the edited article for you every short period of time to prevent the webpage from suddenly closing and causing thousands of words to be written before. All of a sudden it was gone. The disadvantage is that each article will have an automatically saved record, which also occupies an article ID, which is one of the reasons why the article IDs are not consecutive. If you do not need this function, please use the following two files:
12
wp-admin/post-new.phpwp-admin/post.php
Comment out this line:
1
//wp_enqueue_script ('autosave');
5. Rearrange discontinuous article IDs
The following method no longer supports the latest version of WordPress. After completing the above four steps, it is basically guaranteed that the IDs of the articles published in the future will be continuous. However, the IDs of the articles published before are still in chaos. They must be rearranged to ensure that the IDs are continuous. I wrote a PHP script. You can download it from the following URL. After downloading, open it with a text editor. Modify the database information according to the instructions at the beginning. Then upload the PHP file to your blog space. Run it and see OK. , you can go to phpmyadmin to check whether the IDs in the wp_posts table are consecutive. Again, please back up your database before starting. (If you use post id as a fixed link, it may change the URL of all articles, which will affect search engine inclusion; if you use a plug-in to create a new database table, such as a voting plug-in, etc., problems will also occur; if A page with a parent-child relationship has been created in your blog. If you run the following script, this relationship will be lost. Please use it with caution!)... The rest of the text >>
Just add the following code to wp-config.php:
Copy the code as follows:
define('AUTOSAVE_INTERVAL', 120 ); // Set the auto-save interval in seconds, the default is 60
define('WP_POST_REVISIONS', false ); // Disable article revision function
define('WP_POST_REVISIONS', 3); //