WordPress高级用户的5个技巧

WordPress not only gives users the ability to create powerful websites with great features, it also allows users to make customizations to add extra security, streamline deployment and assist with administration.

WordPress不仅使用户能够创建功能强大的强大网站,还使用户可以进行自定义以增加额外的安全性,简化部署并协助管理。

Installing WordPress is very simple and easy, even beginners with a basic knowledge of the web can do it. In this article, we go beyond the basics and discuss 5 tips for WordPress power users:

安装WordPress非常简单容易,即使是具有Web基本知识的初学者也可以做到。 在本文中,我们超越了基础知识,并讨论了WordPress高级用户的5个技巧:

  1. wp-config can reside outside of the root directory

    wp-config可以位于根目录之外
  2. WordPress can be installed via the command line using WP-CLI

    可以使用WP-CLI通过命令行安装WordPress
  3. You can enable SSL for logins and to access the Dashboard

    您可以启用SSL进行登录和访问仪表板
  4. You can easily enable two-factor authentication

    您可以轻松启用两因素身份验证
  5. WordPress can be installed in a subdirectory (and still run it from the web root)

    WordPress可以安装在子目录中(并且仍然可以从Web根目录运行它)

1. wp-config可以驻留在根目录之外 (1. wp-config Can Reside Outside of the Root Directory)

wp-config is the primary WordPress configuration file. It contains your database name, database user and password, unique authentication keys, table prefix and other important information.

wp-config是主要的WordPress配置文件。 它包含您的数据库名称,数据库用户和密码,唯一身份验证密钥,表前缀和其他重要信息。

To add an extra layer of security, you can move wp-config.php outside of the WordPress installation directory. This means for a site installed in the root of your web hosting space (e.g the public_html directory), you can save wp-config.php outside of the web root folder.

为了增加安全性,您可以将wp-config.php移到WordPress安装目录之外。 这意味着对于安装在网站托管空间根目录中的网站(例如public_html目录),您可以将wp-config.php保存在网站根文件夹之外。

You can also create a new directory outside of public_html or you can save wp-config.php in an existing directory, and WordPress just works.

您也可以在public_html之外创建一个新目录,或者可以将wp-config.php保存在现有目录中,而WordPress可以正常工作。

2.可以使用WP-CLI通过命令行安装WordPress (2. WordPress Can Be Installed Via the Command Line Using WP-CLI)

WP-CLI stands for WordPress Command Line Interface. WP-CLI is a set of command-line tools for managing WordPress installations and it’s extremely powerful. You can perform common tasks very easily such as updating WordPress, generating backups, updating plugins and setting up WordPress Multi-site just to name a few.

WP-CLI代表WordPress命令行界面。 WP-CLI是一套用于管理WordPress安装的命令行工具,功能非常强大。 您可以非常轻松地执行常见任务,例如更新WordPress,生成备份,更新插件以及设置WordPress多站点等等。

The WP-CLI project website has all the details on how to install and use WordPress’ command line interface. If you use DreamHost, WP-CLI is installed on all their servers. For more information, you can visit the DreamHost Wiki.

WP-CLI项目网站提供了有关如何安装和使用WordPress命令行界面的所有详细信息。 如果使用DreamHost,则WP-CLI将安装在其所有服务器上。 有关更多信息,您可以访问DreamHost Wiki

3.您可以为登录启用SSL并访问仪表板 (3. You Can Enable SSL for Logins and to Access the Dashboard)

Normally, most of us log into our WordPress sites without SSL enabled, but WordPress allows you to force SSL logins and access to the Administration Dashboard.

通常,我们大多数人都在未启用SSL的情况下登录WordPress网站,但是WordPress允许您强制SSL登录并访问管理仪表板。

To enable this, all you need to do is add the following to your wp-config.php:

为此,您需要做的就是将以下内容添加到wp-config.php

define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
/ That's all, stop editing! Happy blogging. /

You also need an SSL certificate setup for your domain. SSL certificates will cost you around $10 to $50+ annually. The WordPress Administration Over SSL Codex page has all of the details for those wanting to know more.

您还需要为您的域设置SSL证书。 SSL证书每年的费用约为10到50美元。 通过SSL Codex进行WordPress 管理的页面为那些想要了解更多信息的人提供了所有详细信息。

4.您可以轻松启用两因素身份验证 (4. You Can Easily Enable Two-factor Authentication)

While this isn’t a native feature of WordPress and requires a plugin, we felt that it’s related to some of the other tips covered in this article and deserves a mention.

尽管这不是WordPress的本机功能,而是需要插件,但我们认为它与本文介绍的其他一些技巧有关,值得一提。

Two-factor (or two-step) authentication is the process of requiring 2 pieces of information to log in, not just a password. Usually it’s a hardware token such as a Yubikey or a service such as Google Authenticator or Duo.

两因素(或两步)身份验证是要求2条信息登录而不仅仅是密码的过程。 通常,它是诸如Yubikey之类的硬件令牌或诸如Google AuthenticatorDuo之类的服务

Some of the various security plugins also offer two-factor authentication.

各种安全性插件中的一些还提供两因素身份验证。

5. WordPress可以安装在子目录中 (5. WordPress Can Be Installed in a Subdirectory)

Did you know that WordPress allows you to customize your installation directory as well? Normally, you would install WordPress in the root directory (e.g public_html) but WordPress also allows you to install it in a subdirectory http://domain.com/wphere and your site address (URL) will remain same http://domain.com/.

您知道WordPress也允许您自定义安装目录吗? 通常,您可以将WordPress安装在根目录(例如public_html )中,但是WordPress也允许您将其安装在子目录http://domain.com/wphere并且您的站点地址(URL)将保持相同的http://domain.com/

Here is a screen shot of WordPress installation in root directory.

这是根目录下WordPress安装的屏幕快照。

The public_html Directory

Your login URL should look something like this:

您的登录URL应该如下所示:

http://www.domain.com/wp-admin/

http://www.domain.com/wp-admin/

If you install WordPress in its own directory, suppose you have named your directory layer213 your login URL will be something like:

如果将WordPress安装在其自己的目录中,则假设您已将目录命名为layer213,则登录URL将类似于:

http://www.domain.com/layer213/wp-admin/

http://www.domain.com/layer213/wp-admin/

You can name the directory where the WordPress files will be located to anything you like. In my case, you can see I have named it layer213.

您可以将WordPress文件所在的目录命名为任意名称。 就我而言,您可以看到我将其命名为layer213

One reason for wanting to do this is to move the files and directories that clutter up your web root to somewhere else. Your website will still appear to be installed in the web root and your URLs will still work as normal.

想要这样做的原因之一是将使您的Web根目录混乱的文件和目录移动到其他位置。 您的网站似乎仍将安装在Web根目录中,并且您的URL仍将正常运行。

So, in our example your WordPress directory structure would look like:

因此,在我们的示例中,您的WordPress目录结构如下所示:

http://www.domain.com/layer213/wp-admin/

http://www.domain.com/layer213/wp-admin/

Your site address will remain at:

您的站点地址将保持在:

http://www.domain.com/

http://www.domain.com/

That means that users will still visit:

这意味着用户仍将访问:

http://www.domain.com/

http://www.domain.com/

To view your site Dashboard, you would visit:

要查看您的网站信息中心,您可以访问:

http://www.domain.com/layer213/wp-admin/

http://www.domain.com/layer213/wp-admin/

It may seem strange, but it’s a fully supported configuration, covered in more detail at the WordPress Codex.

可能看起来很奇怪,但这是完全受支持的配置,有关详细信息,请参见WordPress Codex

如何在仪表板中更改WordPress地址(URL) (How to Change the WordPress Address (URL) in the Dashboard)

Please note: You should only attempt to do this if you have FTP/SFTP access to your server and you are comfortable getting hands-on with copying and moving files.

请注意:仅当您具有对服务器的FTP / SFTP访问权限并且熟悉复制和移动文件的动手操作时,才应尝试执行此操作。

Let’s walk through the steps needed to install WordPress in its own directory, or if you have already installed it in a subdirectory, how can you change these settings.

让我们逐步介绍将WordPress安装在其自己的目录中所需的步骤,或者如果您已经将其安装在子目录中,则如何更改这些设置。

Log in to your WordPress dashboard go to Settings and General. Below is a screenshot of WordPress Dashboard before moving the WordPress files.

登录到WordPress仪表板,依次转到“设置”和“ 常规” 。 以下是在移动WordPress文件之前WordPress仪表板的屏幕截图。

WordPress Settings Site Address

Now change WordPress Address (URL) with your directory name, whatever you want to name your directory. In my example, I have given it layer213. Site Address (URL) will remain same. Here is a screenshot after changing WordPress Address (URL).

现在,用您的目录名称更改WordPress地址(URL) ,无论您想命名目录如何。 在我的示例中,我给了它layer213网站地址(URL)将保持不变。 这是更改WordPress地址(URL)后的屏幕截图。

WordPress Settings

Now click Save Changes. Don’t worry if you see any errors or your site without any styles. This is normal, we are yet to move the files the new location.

现在,单击“ 保存更改” 。 如果您看到任何错误或网站没有任何样式,请不要担心。 这是正常现象,我们尚未将文件移到新位置。

移动WordPress文件 (Moving the WordPress Files)

Now log in your web hosting Control Panel (cPanel or Plesk etc) or connect via FTP/SFTP. Go to your File Manager and create a new directory. Name it layer213 (change this to whatever name you’d like), the name must be the same as what you entered in the WordPress Dashboard.

现在登录您的虚拟主机控制面板(cPanel或Plesk等)或通过FTP / SFTP连接。 转到文件管理器并创建一个新目录。 将其命名为layer213 (将其更改为您想要的任何名称),该名称必须与您在WordPress仪表板中输入的名称相同。

Select all the WordPress files except the new directory that you created. In my case it is layer213 and move all files to this new directory.

选择除您创建的新目录以外的所有WordPress文件。 在我的情况下是layer213,并将所有文件移动到此新目录。

Copy (Do NOT MOVE!) the index.php and .htaccess files from the new WordPress directory into the root directory of your site (e.g public_html).

将index.php和.htaccess文件从新的WordPress目录复制( 请勿移动! )到您网站的根目录(例如public_html)。

Download index.php to your local computer and open it in a text editor. Find the following line:

index.php下载到本地计算机,然后在文本编辑器中将其打开。 找到以下行:

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

Change it to the following, using your directory name for the WordPress core files:

使用您的WordPress核心文件的目录名称,将其更改为以下内容:

require( dirname( __FILE__ ) . '/layer213/wp-blog-header.php' );

require( dirname( __FILE__ ) . '/layer213/wp-blog-header.php' );

Save the changes and upload it to the root directory (e.g pubic_html) of your web server.

保存更改并将其上载到Web服务器的根目录(例如pubic_html)。

.htaccess在哪里? (Where is .htaccess?)

When you open cPanel and click on File Manager, check the box which says ‘Show hidden files’. Hidden files like .htaccess will then become visible in your File Manager.

打开cPanel并单击“文件管理器”时,选中显示“显示隐藏文件”的框。 诸如.htaccess之类的隐藏文件将在文件管理器中变为可见。

If you’re running WordPress on a Windows IIS Server and have enabled Permalinks, you will be using web.config rather than.htaccess.

如果您在Windows IIS服务器上运行WordPress并启用了永久链接,则将使用web.config而不是.htaccess

登录到仪表板 (Logging into your Dashboard)

Now log into your WordPress Dashboard by typing http://www.domain.com/layer213/wp-admin/ and update your permalink structure if you have it set up. If for any reason WordPress fails to update the permalink structure, it will display the new rewrite rules. Copy and paste these new rules manually into .htaccess file which resides in the root directory.

现在,通过输入http://www.domain.com/layer213/wp-admin/登录到WordPress仪表板,并在设置永久链接结构的情况下对其进行更新。 如果由于任何原因WordPress无法更新永久链接结构,它将显示新的重写规则。 手动将这些新规则复制并粘贴到根目录中的.htaccess文件中。

如果您已经有子目录安装 (If You Already Have a Subdirectory Installation)

If you have already installed WordPress in a subdirectory, you will have to copy index.php and .htaccess files to your root directory.

如果您已经在子目录中安装了WordPress,则必须将index.php.htaccess文件复制到您的根目录中。

Before moving these files, log into your WordPress Dashboard and go to Settings and then the General tab.

在移动这些文件之前,登录到WordPress仪表板,然后依次转到“设置”和“ 常规”选项卡。

Change the Site Address (URL) to your root directory. For example, if the URL is http://domain.com/layer213 then change it to http://domain.com and Save Changes.

站点地址(URL)更改为您的根目录。 例如,如果URL为http://domain.com/layer213则将其更改为http://domain.com保存更改

Don’t worry if you see any errors, this is expected.

如果您看到任何错误,请不要担心,这是预期的。

After changing the Site Address (URL) now copy (don’t move) index.php and .htaccess from layer213 (in my example above) to the root directory of your site (e.g public_html).

更改站点地址(URL)之后,现在将layer213 (在上面的示例中)的 index.php.htaccess复制(不要移动 )到站点的根目录(例如public_html )。

Now open your index.php in any text editor and change following line:

现在,在任何文本编辑器中打开index.php并更改以下行:

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

To the following code:

要以下代码:

require( dirname( __FILE__ ) . '/layer213/wp-blog-header.php' );

require( dirname( __FILE__ ) . '/layer213/wp-blog-header.php' );

Change layer213 to your directory name. Save the changes and then upload the file to the root directory. Your log in address will remain same as before.

layer213更改为您的目录名称。 保存更改,然后将文件上传到根目录。 您的登录地址将保持不变。

You can see a screenshot below after giving WordPress it’s own directory.

给WordPress自己的目录后,您可以在下面看到屏幕截图。

The public_html Directory After Moving WordPress

意见建议 (Suggestions)

Please remember your site will not function correctly when carrying out some of the above steps. If you have lots of visitors you might want to enable Maintenance Mode. You can install a free Maintenance Mode plugin to enable Maintenance Mode with a few clicks.

请记住,执行上述某些步骤时,您的网站将无法正常运行。 如果您有很多访问者,则可能需要启用维护模式。 您可以安装免费的维护模式插件,只需单击几下即可启用维护模式。

翻译自: https://www.sitepoint.com/5-tips-for-wordpress-power-users/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值