wordpress自定义_如何在WordPress中创建自定义永久链接

wordpress自定义

Do you want to create custom permalinks in WordPress for posts, pages, and other post types?

您是否要在WordPress中为帖子,页面和其他帖子类型创建自定义永久链接?

Recently one of our readers asked if it was possible to create their own custom permalinks aka page URL structure in WordPress.

最近,我们的一位读者问,是否有可能在WordPress中创建自己的自定义永久链接又称页面URL结构。

In this article, we will show you how to create custom permalinks in WordPress without affecting your SEO.

在本文中,我们将向您展示如何在WordPress中创建自定义永久链接而不影响您的SEO。

Creating custom permalinks in WordPress

Since this is a comprehensive tutorial on creating custom permalinks in WordPress, we have created an easy to navigate table of content:

由于这是有关在WordPress中创建自定义永久链接的综合教程,因此我们创建了易于浏览的目录:

WordPress中的自定义永久链接是什么? (What is a Custom Permalink in WordPress?)

Permalinks are the permanent URLs of your individual blog posts, pages, and other archive pages on your WordPress site. Custom permalink is basically a URL structure applied to a specific page in WordPress without affecting the rest of your URL structure.

永久链接是WordPress网站上各个博客文章,页面和其他存档页面的永久URL。 自定义永久链接基本上是一种应用于WordPress中特定页面的URL结构,而不会影响其余的URL结构。

WordPress comes with an SEO Friendly URL structure which allows you to use an easy to understand URL structure for both humans and search engines.

WordPress带有SEO友好URL结构 ,可让您为人类和搜索引擎使用易于理解的URL结构。

For example: https://example.com/best-refrigerators-for-tiny-kitchens/

例如:https://example.com/best-refrigerators-for-tiny-kitchens/

This is much better than URLs from the old days: https://example.com/index.php?p=4556

这比以前的URL更好:https://example.com/index.php?p = 4556

WordPress provides website owners with multiple options to choose from. You can view them by visiting Settings » Permalinks page.

WordPress为网站所有者提供了多种选择。 您可以通过访问设置»永久链接页面来查看它们。

Select permalink structure

Aside from changing the main permalink structure, WordPress also offers ways to customize the individual URLs of posts, pages, categories, tags, and other areas of your website.

除了更改主要的永久链接结构外,WordPress还提供了一些方法来自定义帖子,页面,类别,标签和网站其他区域的各个URL。

You can also use WordPress plugins to create completely custom permalinks for specific sections of your website that overrides the default WordPress settings.

您还可以使用WordPress插件为网站的特定部分创建完全自定义的永久链接,以覆盖默认的WordPress设置。

Let’s take a look at all the options one by one. We’ll start with the default built-in options that come with your WordPress website.

让我们一一看一下所有选项。 我们将从WordPress网站随附的默认内置选项开始。

影片教学 (Video Tutorial)

Subscribe to WPBeginner
订阅WPBeginner

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

如何更改WordPress永久链接结构 (How to Change the WordPress Permalink Structure)

If you want to change the whole URL generation scheme for your website, then go to Settings » Permalinks page.

如果要更改网站的整个URL生成方案,请转到“设置”»“永久链接”页面。

Select permalink structure

Simply select a URL structure for your individual posts. You can also use the tags shown on the screen to create a custom structure for your WordPress URLs.

只需为您的各个帖子选择一个URL结构。 您还可以使用屏幕上显示的标签为WordPress URL创建自定义结构。

Don’t forget to click on the Save Changes button to store your changes.

不要忘记单击“保存更改”按钮来存储您的更改。

We recommend using a URL structure that includes the post name in the URL. This makes your URLs more SEO friendly and meaningful.

我们建议使用URL结构,该结构在URL中包含帖子名称。 这使您的URL更加SEO友好和有意义。

Note: You should change to a SEO friendly permalinks for all new WordPress blogs and websites. However, if you have an existing website that’s already getting traffic from search engines, then changing permalinks can affect your SEO rankings.

注意:您应该为所有新的WordPress博客网站更改为SEO友好的永久链接。 但是,如果您现有的网站已经从搜索引擎获得流量,则更改永久链接可能会影响您的SEO排名。

如何在WordPress中更改类别和标签URL前缀 (How to Change the Category and Tag URL Prefix in WordPress)

By default, WordPress uses /category/ as the base for your category URLs and /tag/ for the tags pages. For example:

默认情况下,WordPress使用/ category /作为类别URL的基础,并使用/ tag /作为标签页面的基础。 例如:

https://example.com/category/technology/ https://example.com/tag/fintech/

https://example.com/category/technology/ https://example.com/tag/fintech/

Category and tag base

You can change these base prefixes from the Settings » Permalinks page to anything that you like. For example,

您可以将这些基本前缀从“ 设置”»“永久链接”页面更改为所需的任何内容。 例如,

https://example.com/topics/technology/ (for category pages) https://example.com/hashtag/fintech (for tag pages)

https://example.com/topics/technology/(用于类别页面)https://example.com/hashtag/fintech(用于标签页面)

如何更改单个WordPress帖子或页面URL (How to Change Individual WordPress Post or Page URL)

Once you have the permalink structure setup, WordPress uses that as a template for all links on your site. However, you do have the option to modify the URL slug aka keywords inside the URL structure for individual posts, pages, and custom post types.

设置完永久链接结构后,WordPress会将其用作网站上所有链接的模板。 但是,您确实可以选择针对单个帖子,页面和自定义帖子类型在URL结构中修改URL子句 aka关键字。

You can customize the slug part of the URL from the post edit screen inside the WordPress content editor.

您可以在WordPress内容编辑器中的帖子编辑屏幕中自定义URL的子弹部分。

Simply edit the post, page, or custom post type and click on the title field. You’ll notice the Permalink field appears on top of it.

只需编辑帖子,页面或自定义帖子类型,然后单击标题字段。 您会注意到“永久链接”字段显示在其顶部。

Edit post slug to create custom URL

Go ahead and click on the Edit button next to it, and then change the URL slug to a custom permalink. Once you are done, click on the Save button to store the new permalink.

继续并单击它旁边的“编辑”按钮,然后将URL子段更改为自定义的永久链接。 完成后,单击“保存”按钮以存储新的永久链接。

Customize post permalink

You can use this method for all post types including WooCommerce products, MemberPress courses, etc.

您可以对所有帖子类型使用此方法,包括WooCommerce产品, MemberPress课程等。

如何更改WordPress类别或标签URL (How to Change WordPress Category or Tag URL)

In the earlier step, we showed you how to modify the category and tag base prefix in WordPress. In this step, we will show you how to change the URL keywords for an individual category or tag.

在前面的步骤中,我们向您展示了如何在WordPress中修改类别和标签基础前缀。 在此步骤中,我们将向您展示如何更改单个类别或标签的URL关键字。

Simply go to Posts » Categories page and click on the Edit link below the category you want to customize.

只需转到帖子»类别页面,然后单击您要自定义类别下方的编辑链接。

Editing a category details in WordPress

WordPress will now load the category details. From here, you can change the category slug to customize its permalink.

WordPress现在将加载类别详细信息。 在这里,您可以更改类别标签以自定义其永久链接。

Change category slug to customize permalink

Similarly, you can edit an individual tag by visiting Posts » Tags page.

同样,您可以通过访问帖子»标签页面来编辑单个标签。

Edit a tag

You can also edit any custom taxonomies using the same method.

您也可以使用相同的方法编辑任何自定义分类法。

如何在WordPress中更改作者页面URL (How to Change Author Page URL in WordPress)

WordPress automatically adds the ‘/author/’ base to URLs leading to author archive pages. For example:

WordPress会自动将“ / author /”库添加到指向作者存档页面的URL中。 例如:

https://example.com/author/jsmith/

https://example.com/author/jsmith/

The problem is that WordPress does not come with an option to change the author URL base or the slug.

问题是WordPress没有附带更改作者URL库或子词条的选项。

Luckily, as the saying goes, there is a plugin that can help.

幸运的是,俗话说,有一个可以提供帮助的插件。

Simply install and activate the Edit Author Slug. For details, see our step by step guide on how to install a WordPress plugin.

只需安装并激活Edit Author Slug即可 。 有关详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, go to Users » All Users page. Next, click on the ‘Edit’ link below a username.

激活后,转到用户»所有用户页面。 接下来,点击用户名下方的“编辑”链接。

Editing a user details in WordPress

On the next page, scroll down to the Edit Author Slug section, and you will be able to choose an author slug or add your own. Don’t forget to click on the save changes button to store your settings.

在下一页上,向下滚动到“编辑作者信息”部分,您将可以选择作者信息或添加自己的信息。 不要忘记单击“保存更改”按钮来存储您的设置。

If you want to change the author permalink base, then simply head over to the Settings » Edit Author Slug page. Here you will see an option to change the author base and even choose different author bases for users with different user roles.

如果要更改作者永久链接库,则只需转到“ 设置”»“编辑作者子弹”页面。 在这里,您将看到一个选项,用于更改作者基础,甚至为具有不同用户角色的用户选择不同的作者基础。

Change author base

For more details, see our guide on how to change author URL slug and base in WordPress.

有关更多详细信息,请参见有关如何更改WordPress中的作者URL链接和基础的指南

如何在WordPress中创建完全自定义的永久链接 (How to Create Completely Custom Permalinks in WordPress)

All the above methods allows you to customize WordPress permalinks to a certain extent. However, they cannot help you create completely custom permalinks.

以上所有方法都可以在一定程度上自定义WordPress永久链接。 但是,它们不能帮助您创建完全自定义的永久链接。

That’s because WordPress by default doesn’t offer this functionality.

这是因为默认情况下WordPress不提供此功能。

Luckily, there’s a plugin that can help. If you want to override the default WordPress URL structure for specific sections on your site, then follow the steps here.

幸运的是,有一个可以提供帮助的插件。 如果要覆盖网站上特定部分的默认WordPress URL结构,请按照此处的步骤进行操作。

The first thing you need to do is install and activate the Custom Permalinks plugin. For more details, see our step by step guide on how to install a WordPress plugin.

您需要做的第一件事是安装并激活Custom Permalinks插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, you need to edit the post where you want to create a custom permalink. Instead of editing the permalink field at the top, you’ll find the option to create a custom permalink below the editor.

激活后,您需要在要创建自定义永久链接的地方编辑帖子。 您无需在顶部编辑永久链接字段,而是在编辑器下方找到用于创建自定义永久链接的选项。

Creating a completely custom permalink for a post

Similarly, you can also create custom permalinks for categories. Go to Posts » Categories page and click on the edit link below the category that you want to change.

同样,您也可以为类别创建自定义永久链接。 转到帖子»类别页面,然后单击要更改的类别下面的编辑链接。

Editing a category details in WordPress

On the category details page, you’ll find the option to create a custom permalink for that particular category. You can even create a URL without the category base prefix.

在类别详细信息页面上,您会找到用于为该特定类别创建自定义永久链接的选项。 您甚至可以创建没有类别基本前缀的URL。

Editing the category permalink

You can manage and disable all your custom permalinks by clicking on the ‘Custom Permalinks’ menu in the admin sidebar.

您可以通过点击管理侧边栏中的“自定义永久链接”菜单来管理和禁用所有自定义永久链接。

Manage your custom permalinks

Simply select the custom permalinks you want to delete and then click on the Bulk Actions menu to select ‘Delete permalinks’ option.

只需选择要删除的自定义永久链接,然后单击“批量操作”菜单以选择“删除永久链接”选项。

After that click on the ‘Apply’ button and the plugin will remove those custom permalinks. The deleted permalink will be replaced by your default WordPress permalink scheme.

之后,点击“应用”按钮,插件将删除这些自定义的永久链接。 删除的永久链接将替换为您的默认WordPress永久链接方案。

如何设置永久链接重定向并避免404错误 (How to Setup Permalink Redirects and Avoid 404 Errors)

WordPress automatically handles changes made to post and page URLs. However, it may not set up redirects for your custom author permalinks or completely customized permalinks.

WordPress自动处理对帖子和页面URL所做的更改。 但是,它可能无法为您的自定义作者永久链接或完全自定义的永久链接设置重定向。

In that case, you’ll need to set up proper redirects to avoid 404 errors on your website.

在这种情况下,您需要设置适当的重定向以避免网站上出现404错误

First, you need to install and activate the Redirection plugin.

首先,您需要安装并激活重定向插件。

Upon activation, you need to visit Tools » Redirection page to set up redirects. You need to add the old link in the ‘Source URL’ field and the new URL in the ‘Target URL’ field.

激活后,您需要访问工具»重定向页面以设置重定向。 您需要在“源URL”字段中添加旧链接,并在“目标URL”字段中添加新URL。

Setup redirects

After that click on the ‘Add redirect’ button to save your changes. For more details, see our beginner’s guide to setting up redirects in WordPress.

之后,点击“添加重定向”按钮以保存您的更改。 有关更多详细信息,请参阅我们的初学者指南以在WordPress中设置重定向

We hope this article helped you learn how to create custom permalinks in WordPress. You may also want to see our ultimate WordPress SEO guide to get more search traffic to your website.

我们希望本文能帮助您学习如何在WordPress中创建自定义永久链接。 您可能还想查看我们的终极WordPress SEO指南,以获取更多到您网站的访问量。

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/how-to-create-custom-permalinks-in-wordpress/

wordpress自定义