Table of Contents
完美实现wordpress禁止文章修订和自动保存的方法,wordpress自动保存
wordpress38发布文章id不连续怎解决
wordpress怎关闭自动保存草稿功可以?
Home php教程 php手册 完美实现wordpress禁止文章修订和自动保存的方法,wordpress自动保存

完美实现wordpress禁止文章修订和自动保存的方法,wordpress自动保存

Jun 13, 2016 am 09:22 AM
wordpress prohibit Auto save

完美实现wordpress禁止文章修订和自动保存的方法,wordpress自动保存

使用Wordpress这么久一直很讨厌wordpress的文章修订和自动保存功能,也使用过超级开关插件可以禁止wordpress文章修订和自动保存功能,但是自己博客的插件已经够多的了,只好通过修改wordpress主程序来实现禁止文章修订和自动保存功能。但是这种方法有个不好的地方就是,每次wordpress升级,就得再改动一次wordpress源码,实在是很麻烦的。今天无意中撞到了ZWW博客上发现这个非插件免修改源码实现wordpress禁止文章修订和自动保存的方法,分享给大家吧!

使用方法很简单,只要在主题目录中的functions.php添加相应代码就行了,代码如下:

复制代码 代码如下:


/* 移除自动保存和修订版本 */ 
remove_action('pre_post_update', 'wp_save_post_revision' );  
add_action( 'wp_print_scripts', 'disable_autosave' );  
function disable_autosave(){  
    wp_deregister_script('autosave');  

测试环境:WordPress 3.1.2,原理上 3.0 以上都支持。

wordpress38发布文章id不连续怎解决

如果你不是特别在意,连不连续也是无关紧要的,本文对你来说也没多大意义了。
一、禁用文章修订版
所谓的文章修订版就是你每次修改一次文章,它都会自动帮你保存修改之前的文章版本,专业术语叫做版本控制,这样保证了在误修改的情况下可以还原之前的内容,这个在维基文档的维护方面是有很大帮助的,但是作为我们的小博客,似乎没多大用处,而且这个修订版在数据库中是占据一个ID的,这也是导致文章ID不连续的问题之一。要想禁用文章修订版,可以在 wp-config.php文件中添加:

1

define('WP_POST_REVISIONS', false);

二、删除文章修订版
禁用了文章修订版之后,数据库中还是保存着之前已经创建的文章修订版,这些其实已经没多大用处,而且占着ID,我们可以将它删除。至于怎么删除,可以在 phpmyadmin 中执行以下SQL语句(做好备份):

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';

三、删除不必要的附件
相信很多博友在发布文章都会同时上传/插入一些附件,如图像、视频、音乐等,这些附件可以在WordPress管理后台 – 媒体库中看到,不同媒体对应了不同的文章。可是你要注意的是这些媒体也是占据着文章ID的,它们与文章都保存在同一个数据库表wp_posts中。如果你特别追求文章的ID一定要完美无缺地连续,请不要在发布文章的时候上传/插入这些媒体,并请在WordPress管理后台 – 媒体库中,删除之前上传的媒体(注意这个操作不只是删除记录,而且会删除你上传的文件),需要的话请用FTP重新上传这些文件。
四、禁用自动保存
自动保存的好处是你在编辑文章的时候,每隔一小段时间系统会自动帮你保存编辑的文章,防止网页突然关闭,导致之前写的几千字哗啦一下全没了。缺点是每篇都文章都会有一个自动保存的记录,同样占据一个文章ID,也是文章ID不连续的原因之一,如果你不需要这个功能,请在以下两个文件中:

12

wp-admin/post-new.phpwp-admin/post.php

注释掉这行:

1

//wp_enqueue_script('autosave');

五、重新排列不连续的文章ID
以下方法已不支持最新版WordPress。完成以上四步,基本上可以保证以后发布的文章ID都会是连续的了,但是之前已经发布的文章ID还是一片混乱,得把他们重新排列,以保证是ID是连续的。我写了一个PHP脚本,你可以通过以下网址下载,下载后用文本编辑器打开,根据开头的说明修改数据库信息,然后将该PHP文件上传至你的博客空间,运行一下看到OK就可以了,你可以到phpmyadmin中查看wp_posts表中的id是不是连续的了。还是那句话,开始之前请先备份你的数据库。(如果你使用了post id作为固定链接,那么将可能改变所有文章的网址,会影响搜索引擎收录;如果你用的插件建立了新的数据库表,如投票插件等,也将会出现问题;如果你的博客中创建了父子关系的页面,运行了以下脚本将会失去此关系。请慎用!)...余下全文>>
 

wordpress怎关闭自动保存草稿功可以?

只需在wp-config.php中加入以下代码即可:
复制代码代码如下:
define('AUTOSAVE_INTERVAL', 120 ); // 设置自动保存间隔,单位是秒,默认60
define('WP_POST_REVISIONS', false ); // 禁用文章修订功能
define('WP_POST_REVISIONS', 3); //
 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

How to build a website for wordpress host How to build a website for wordpress host Apr 20, 2025 am 11:12 AM

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

How to change the head image of the wordpress theme How to change the head image of the wordpress theme Apr 20, 2025 am 10:00 AM

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance >Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

What are the plugins for wordpress blocking ip What are the plugins for wordpress blocking ip Apr 20, 2025 am 08:27 AM

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

How to view the front-end of WordPress How to view the front-end of WordPress Apr 20, 2025 am 10:30 AM

You can view the WordPress front-end by logging into the dashboard and switching to the View Sites tab; automate the viewing process with a headless browser; installing the WordPress plugin to preview the front-end within the dashboard; viewing the front-end via a local URL (if WordPress is set locally).

How to cancel the editing date of wordpress How to cancel the editing date of wordpress Apr 20, 2025 am 10:54 AM

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

How to import the source code of wordpress How to import the source code of wordpress Apr 20, 2025 am 11:24 AM

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

How to write a header of a wordpress How to write a header of a wordpress Apr 20, 2025 pm 12:09 PM

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

See all articles