wordpress配置_您可能不知道的15个有用的WordPress配置技巧

wordpress配置

WP-config is one of the most powerful files on your WordPress site, and it plays an important role in how WordPress works behind the scenes. There are some very useful WordPress configuration tricks that most beginners don’t know about. In this article, we will share some of the most useful WordPress configuration tricks that will help you troubleshoot, optimize, and secure your WordPress site.

WP-config是WordPress网站上功能最强大的文件之一,它在WordPress幕后工作中起着重要作用。 大多数初学者都不知道有一些非常有用的WordPress配置技巧。 在本文中,我们将分享一些最有用的WordPress配置技巧,可帮助您解决,优化和保护WordPress网站。

Useful WordPress configuration tricks
如何使用这些WordPress配置技巧? (How to Use these WordPress Configuration Tricks?)

WordPress comes with a powerful configuration file called wp-config.php. It is located in the root folder of every WordPress site and contains important configuration settings.

WordPress随附一个功能强大的配置文件wp-config.php 。 它位于每个WordPress网站的根文件夹中,并且包含重要的配置设置。

To learn more, see our guide on how to edit wp-config.php file in WordPress.

要了解更多信息,请参阅有关如何在WordPress中编辑wp-config.php文件的指南。

All the best WordPress hosting companies come with 1-click WordPress installation which means you would never need to edit the wp-config.php file during the installation. This is the main reason why many users are not familiar with the power of this file.

所有最好的WordPress托管公司都附带一键式WordPress安装 ,这意味着您在安装过程中将不需要编辑wp-config.php文件。 这是许多用户不熟悉此文件功能的主要原因。

You can use the wp-config file to troubleshoot, optimize, and secure your WordPress site.

您可以使用wp-config文件对WordPress网站进行故障排除,优化和保护。

The wp-config.php file is a powerful tool, and a tiny mistake in the code can make your website inaccessible. You should only edit this file when necessary and always create a complete WordPress backup before making any changes,

wp-config.php文件是一个功能强大的工具,并且代码中的微小错误会使您的网站无法访问。 您只应在必要时编辑此文件,并在进行任何更改之前始终创建完整的WordPress备份

That being said, let’s take a look at some handy WordPress configuration tricks that you can use on your website.

话虽这么说,让我们来看看您可以在网站上使用的一些方便的WordPress配置技巧。

1.基本的WordPress配置设置 (1. The Basic WordPress Configuration Settings)

By default, you just need to fill in the database settings during WordPress installation. If you don’t have a wp-config.php file present, then you will be asked to create one by filling in your database information.

默认情况下,您只需要在WordPress安装过程中填写数据库设置即可。 如果您没有wp-config.php文件,那么将要求您通过填写数据库信息来创建一个文件。

Default WordPress configuration settings

WordPress will try to automatically save these settings by generating a wp-config.php file. However, if it fails, then you will need to add them manually.

WordPress将尝试通过生成wp-config.php文件来自动保存这些设置。 但是,如果失败,则需要手动添加它们。

To do that, you will need to connect with your website using an FTP client. Once connected, you will need to rename the wp-config-sample.php file to wp-config.php.

为此,您将需要使用FTP客户端连接到您的网站。 连接后,您需要将wp-config-sample.php文件重命名为wp-config.php。

Rename wp-config-sample.php file

After that, you can go ahead and edit the newly created wp-config.php file. You will need to add your database information by changing the following lines:

之后,您可以继续编辑新创建的wp-config.php文件。 您将需要通过更改以下行来添加数据库信息:


define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');

Don’t forget to save your changes and upload the file back to the server.

不要忘记保存您的更改并将文件上传回服务器。

2.在WordPress中添加安全密钥 (2. Adding Security Keys in WordPress)

The default WordPress installation automatically adds security keys to your configuration file. These security keys are used to add an extra security layer to your WordPress login and cookie authentication.

默认的WordPress安装会自动将安全密钥添加到您的配置文件中。 这些安全密钥用于为您的WordPress登录名和cookie身份验证添加一个额外的安全层。

You can always regenerate security keys if you feel someone may be accessing your website without proper authentication. Changing security keys will log out all logged in users.

如果您发现有人未经适当的身份验证可能正在访问您的网站,则可以始终重新生成安全密钥 。 更改安全密钥将注销所有已登录的用户。


define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

For more information, see our article on WordPress security keys and how to use them.

有关更多信息,请参阅关于WordPress安全密钥及其使用方法的文章。

3.更改WordPress表前缀 (3. Change WordPress Table Prefix)

A typical default WordPress installation adds a wp_ prefix to all WordPress database table names. Some WordPress security experts believe that changing the table prefix can make your WordPress database more secure.

典型的默认WordPress安装会将wp_前缀添加到所有WordPress数据库表名称中。 一些WordPress安全专家认为,更改表前缀可以使WordPress数据库更安全。

To do that you, need to change the following line in your WordPress configuration.

为此,您需要在WordPress配置中更改以下行。


$table_prefix = 'wp_';

If you are doing this for an existing website, then you will also need to change the table prefix in your WordPress database. To do that, see our article on how to change the WordPress database prefix.

如果对现有网站执行此操作,则还需要更改WordPress数据库中的表前缀。 为此,请参阅有关如何更改WordPress数据库前缀的文章

4.打开WordPress中的调试 (4. Turn on Debugging in WordPress)

WordPress comes with a neat debugging feature that allows you to see or hide WordPress errors when in debug mode. To turn this on, you will need to add this rule in your WordPress configuration file.

WordPress具有简洁的调试功能,可让您在调试模式下查看或隐藏WordPress错误。 要启用此功能,您需要在WordPress配置文件中添加此规则。


define( 'WP_DEBUG', true );

You can also turn on debugging while hiding the errors on your website and saving them in a log file instead. To do that, add the following lines to your configuration settings.

您还可以打开调试,同时将错误隐藏在网站上,然后将其保存在日志文件中。 为此,将以下行添加到您的配置设置。


define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

This will create a debug.log file inside wp-content folder of your website and store all debugging errors and notices inside the log file.

这将在您网站的wp-content文件夹中创建一个debug.log文件,并将所有调试错误和通知存储在日志文件中。

5.更改您的网站或WordPress地址 (5. Changing Your Site or WordPress Address)

Normally, you can set your WordPress and Site URLs from Settings » General page. However, you may not be able to do that if you don’t have access to your WordPress site, seeing redirect errors, or have just moved your site.

通常,您可以从“设置”»“常规”页面设置 WordPress和站点URL。 但是,如果您无权访问WordPress网站,看到重定向错误或刚刚移动了网站,则可能无法执行此操作。

In that case, you can change your site and WordPress URLs via wp-config.php file by adding the following lines:

在这种情况下,您可以通过添加以下几行来通过wp-config.php文件更改站点和WordPress URL:


define('WP_HOME', 'http://www.example.com');
define('WP_SITEURL', 'http://www.example.com');

Don’t forget to replace example.com with your own domain name.

不要忘记用您自己的域名替换example.com。

6.覆盖文件权限 (6. Override File Permissions)

WordPress allows you to override file permissions if your host has restrictive permissions for all user files. Most users do not need this, but it exists for those who need it.

如果主机对所有用户文件都具有限制性权限,则WordPress允许您覆盖文件权限。 大多数用户不需要它,但是对于需要它的人来说,它是存在的。


define('FS_CHMOD_FILE', 0644);
define('FS_CHMOD_DIR', 0755);

To learn more about file permissions, see our article on how-to fix file and folder permissions error in WordPress.

要了解有关文件权限的更多信息,请参阅有关如何修复WordPress中的文件和文件夹权限错误的文章

7.更改修订版设置 (7. Changing Post Revision Settings)

WordPress has a very useful a post revisions feature which allows you to undo changes to your posts and pages by reverting back to a previous version or an autosave.

WordPress具有非常有用的后期修订功能,该功能可让您通过恢复为先前版本或自动保存来撤消对帖子和页面的更改。

You can disable or change post revision settings through the configuration file. Here are different post revision settings that you can use.

您可以通过配置文件禁用或更改修订版设置。 您可以使用以下不同的修订版设置。

You can change how often WordPress stores an autosave as a revision by adding the following line:

您可以通过添加以下行来更改WordPress将自动保存作为修订版本存储的频率:


define('AUTOSAVE_INTERVAL', 120); // in seconds

Some articles on your site may have dozens of post revisions depending on how long it took to write them. If you think that feature annoys you, then you can limit the number of revisions per post.

您网站上的某些文章可能会有数十篇文章的修订版本,具体取决于撰写这些文章的时间。 如果您认为该功能烦人,则可以限制每个帖子的修订数量。


define('WP_POST_REVISIONS', 10);

If for some reason, you want to disable the post revisions feature altogether (not recommended at all), then you can use the following code to disable post revisions.

如果出于某种原因,您想完全禁用发布修订版功能(完全不建议这样做),则可以使用以下代码禁用发布修订版。


define( 'WP_POST_REVISIONS', false );

8.更改WordPress废纸Settings设置 (8. Changing WordPress Trash Settings)

WordPress comes with a recycle bin feature called Trash. When a user sends a post to trash, it is still stored on your website for next 30 days as trash. After that time, WordPress automatically deletes them forever.

WordPress带有称为垃圾箱的回收站功能。 当用户向垃圾箱发送帖子时,该帖子仍会作为垃圾箱存储在您的网站上,持续30天。 在那之后,WordPress会自动将其永久删除。

You can change this behavior by changing the number of days you want to keep the trash.

您可以通过更改要保留垃圾的天数来更改此行为。


define( 'EMPTY_TRASH_DAYS', 15 ); // 15 days

If you do not like this feature, then you can disable it by adding the function below:

如果您不喜欢此功能,则可以通过添加以下功能来禁用它:


define('EMPTY_TRASH_DAYS', 0 );

Note: Using zero means your posts will be deleted permanently. WordPress would not ask for confirmation when you click on Delete Permanently. Any accidental click could cost you…

注意:使用零表示您的帖子将被永久删除。 当您单击永久删除时,WordPress不会要求您进行确认。 任何意外点击都可能使您付出代价……

To learn more, see our article on how to limit or disable automatic empty trash feature in WordPress.

要了解更多信息,请参阅有关如何限制或禁用WordPress中的自动清空垃圾桶功能的文章

9.将FTP / SSH常量添加到WordPress配置 (9. Adding FTP/SSH Constants to WordPress Configuration)

By default, WordPress allows you to upgrade WordPress core, themes, and plugins from the admin dashboard. There are some hosts that require an FTP or SSH connection everytime you try to upgrade, or install a new plugin.

默认情况下,WordPress允许您从管理仪表盘升级WordPress核心,主题和插件。 每当您尝试升级或安装新插件时,有些主机都需要FTP或SSH连接。

WordPress asking for FTP information

By using the codes, you can set the FTP or SSH constants and never have to worry about it again.

通过使用这些代码,您可以设置FTP或SSH常数,而无需再担心它。


// forces the filesystem method: "direct", "ssh", "ftpext", or "ftpsockets"
define('FS_METHOD', 'ftpext');
// absolute path to root installation directory
define('FTP_BASE', '/path/to/wordpress/');
// absolute path to "wp-content" directory
define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/');
// absolute path to "wp-plugins" directory
define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/');
// absolute path to your SSH public key
define('FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub');
// absolute path to your SSH private key
define('FTP_PRIVKEY', '/home/username/.ssh/id_rsa');
// either your FTP or SSH username
define('FTP_USER', 'username');
// password for FTP_USER username
define('FTP_PASS', 'password');
// hostname:port combo for your SSH/FTP server
define('FTP_HOST', 'ftp.example.org:21'); 

Note: Don’t forget to replace the WordPress path and ftp.example.com with your own FTP Host information.

注意:不要忘记用您自己的FTP主机信息替换WordPress路径和ftp.example.com。

10.允许自动数据库修复 (10. Allow Automatic Database Repair)

WordPress comes with a built-in feature to automatically optimize and repair WordPress database. However, this feature is turned off by default.

WordPress具有内置功能,可以自动优化和修复WordPress数据库 。 但是,此功能默认情况下处于关闭状态。

To enable this feature you need to add the following line to your WordPress configuration file.

要启用此功能,您需要将以下行添加到WordPress配置文件中。


define('WP_ALLOW_REPAIR', true);

After adding this, you need to visit the following URL to optimize and repair WordPress database

添加此内容后,您需要访问以下URL以优化和修复WordPress数据库

http://example.com/wp-admin/maint/repair.php

http://example.com/wp-admin/maint/repair.php

Don’t forget to replace example.com with your own domain name. You will see a simple page with the options to repair or repair and optimize the database. You don’t need to be logged in to access this page.

不要忘记用您自己的域名替换example.com。 您将看到一个简单的页面,其中包含用于修复或修复和优化数据库的选项。 您无需登录即可访问此页面。

Optimize and repair WordPress database
11.增加PHP内存限制 (11. Increase PHP Memory Limit)

Some of the most common WordPress errors are caused by PHP memory exhausted. You can increase the PHP memory limit through wp-config.php file. Simply paste the code below:

一些最常见的WordPress错误是由于PHP内存耗尽而引起的。 您可以通过wp-config.php文件增加PHP内存限制。 只需粘贴以下代码:


define('WP_MEMORY_LIMIT', '128M');

12.移动wp-content目录 (12. Moving wp-content Directory)

WordPress allows you to move your wp-content directory. Some experts believe that it can help strengthen WordPress security.

WordPress允许您移动wp-content目录。 一些专家认为,它可以帮助加强WordPress的安全性。

You will need to add the following code to your wp-config.php file:

您需要将以下代码添加到wp-config.php文件中:


define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' );
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');
define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins' );
define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins');

Don’t forget to replace example.com with your own domain name.

不要忘记用您自己的域名替换example.com。

13.使用自定义用户表 (13. Use Custom User Tables)

By default, WordPress saves all user data in the tables wp_users and wp_usermeta. By using the function below, you can specify the table where you want your user information stored.

默认情况下,WordPress将所有用户数据保存在表wp_users和wp_usermeta中。 通过使用以下功能,您可以指定要存储用户信息的表。


define('CUSTOM_USER_TABLE', $table_prefix.'my_users');
define('CUSTOM_USER_META_TABLE', $table_prefix.'my_usermeta');

14.启用多站点网络 (14. Enable Multi-Site Network)

Each WordPress site comes with a built-in multisite feature which allows you to create multiple WordPress sites using the same installation. To learn more, see our complete guide on how to install and setup WordPress multisite network.

每个WordPress网站都具有内置的多站点功能,使您可以使用同一安装来创建多个WordPress网站。 要了解更多信息,请参阅有关如何安装和设置WordPress多站点网络的完整指南。

You can enable multisite functionality by adding the following line to your WordPress configuration file:

您可以通过将以下行添加到WordPress配置文件中来启用多站点功能:


define('WP_ALLOW_MULTISITE', true);

15.保护您的WordPress配置文件 (15. Securing Your WordPress Configuration File)

As you can see, the wp-config.php file contains really important WordPress settings. By default it is located in the root WordPress folder, but you can move it. It can be moved outside your public_html directory, so users cannot access it. WordPress knows by default to look in other directories if the files is not found in the WordPress root folder.

如您所见,wp-config.php文件包含非常重要的WordPress设置。 默认情况下,它位于WordPress根文件夹中,但是您可以移动它。 可以将其移到public_html目录之外,因此用户无法访问它。 如果在WordPress根文件夹中找不到文件,则默认情况下WordPress知道会查找其他目录。

You can also add the following code to your .htaccess file to limit access to this file.

您还可以将以下代码添加到您的.htaccess文件中,以限制对此文件的访问。


# Protect wp-config.php
<Files wp-config.php>
    order allow,deny
    deny from all
</Files>

We hope this article helped you learn some useful WordPress configuration tricks that you didn’t know. You may also want to see our mega list of 55+ most wanted WordPress tips, tricks, and hacks that you can use on your site.

我们希望本文能帮助您学习一些您不知道的有用的WordPress配置技巧。 您可能还希望查看我们的大型列表,其中包含55+个最需要的WordPress技巧,窍门和hack ,您可以在自己的网站上使用它们。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/useful-wordpress-configuration-tricks-that-you-may-not-know/

wordpress配置

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值