samiahmedsiddiqui / custom-permalinks
在WordPress中为每篇文章设置自定义固定链接。
Requires
- php: >=7.0
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ~2.1.3
- squizlabs/php_codesniffer: 3.10.1
- wp-coding-standards/wpcs: ~3.1.0
This package is auto-updated.
Last update: 2024-09-20 13:23:47 UTC
README
ℹ️ 如果在升级到最新版本后发现任何导致网站损坏的问题,请通过WordPress 论坛或GitHub报告问题,并提供完整的信息以重现问题,并恢复到旧版本。您可以从这里下载任何旧版本:https://wordpresstheme.cn/plugins/custom-permalinks/advanced/
根据您的需求设计您的网站。将任何文章、页面、标签或分类的URL设置为任何您想要的内容。旧固定链接将正确重定向到新地址。自定义固定链接让您对网站结构拥有完全控制权。
⚠️ 此插件不是WordPress内置固定链接系统的替代品。请首先检查WordPress管理的“固定链接”设置页面,以确保它已经满足您的需求。
此插件仅适用于为单个文章、页面、标签或分类分配自定义固定链接。它不会应用整个固定链接结构,也不会自动将分类的自定义固定链接应用于该分类中的文章。
过滤器
在$_SERVER
变量中添加PATH_INFO
add_filter( 'custom_permalinks_path_info', '__return_true' );
禁用重定向
要禁用此插件提供的完整重定向功能,请添加如下所示的过滤器
function yasglobal_avoid_redirect( $permalink ) { return true; } add_filter( 'custom_permalinks_avoid_redirect', 'yasglobal_avoid_redirect' );
禁用特定重定向
要禁用此插件处理的任何特定重定向,请添加如下所示的过滤器
function yasglobal_avoid_redirect( $permalink ) { // Replace 'testing-hello-world/' with the permalink you want to avoid if ( 'testing-hello-world/' === $permalink ) { return true; } return false; } add_filter( 'custom_permalinks_avoid_redirect', 'yasglobal_avoid_redirect' );
排除要处理的固定链接
要排除任何要由插件处理的固定链接,请添加如下所示的过滤器
function yasglobal_xml_sitemap_url( $permalink ) { if ( false !== strpos( $permalink, 'sitemap.xml' ) ) { return '__true'; } return; } add_filter( 'custom_permalinks_request_ignore', 'yasglobal_xml_sitemap_url' );
排除文章类型
要从任何文章类型中删除自定义固定链接表单,请添加如下所示的过滤器
function yasglobal_exclude_post_types( $post_type ) { // Replace 'custompost' with your post type name if ( 'custompost' === $post_type ) { return '__true'; } return '__false'; } add_filter( 'custom_permalinks_exclude_post_type', 'yasglobal_exclude_post_types' );
排除文章
要从任何文章中排除自定义固定链接表单(基于ID、模板等),请添加如下所示的过滤器
function yasglobal_exclude_posts( $post ) { if ( 1557 === $post->ID ) { return true; } return false; } add_filter( 'custom_permalinks_exclude_posts', 'yasglobal_exclude_posts' );
允许带重音符号的字母
要允许带重音符号的字母,请在您的主题的functions.php
中添加以下行
function yasglobal_permalink_allow_accents() { return true; } add_filter( 'custom_permalinks_allow_accents', 'yasglobal_permalink_allow_accents' );
允许大写字母
要允许大写字母/单词,请在您的主题的functions.php
中添加以下行
function yasglobal_allow_uppercaps() { return true; } add_filter( 'custom_permalinks_allow_caps', 'yasglobal_allow_uppercaps' );
允许多余的连字符
要允许多余的连字符,请在您的主题的functions.php
中添加以下行
function yasglobal_redundant_hyphens() { return true; } add_filter( 'custom_permalinks_redundant_hyphens', 'yasglobal_redundant_hyphens' );
在保存之前操纵固定链接
要在保存之前更改固定链接,请使用custom_permalink_before_saving
过滤器。以下是一个示例,说明它是如何工作的。
function yasglobal_permalink_before_saving( $permalink, $post_id ) { // Check trialing slash in the permalink. if ( substr( $permalink, -1 ) !== '/' ) { // If permalink doesn't contain trialing slash then add one. $permalink .= '/'; } return $permalink; } add_filter( 'custom_permalink_before_saving', 'yasglobal_permalink_before_saving', 10, 2 );
移除like
查询
要移除like
查询以使其工作,请在您的主题的functions.php
中添加以下行
add_filter( 'cp_remove_like_query', '__return_false' );
注意:如果您在升级到v1.2.9
后遇到URL无法正常工作的情况,请使用custom_permalinks_like_query
过滤器。
感谢支持
由于我已将电子邮件支持放在首位,因此我并不总是在WordPress.org论坛上提供Custom Permalinks插件的主动支持。仅对购买Custom Permalinks Premium的人提供一对一的电子邮件支持。
错误报告
欢迎在GitHub上提交Custom Permalinks的错误报告。请注意,GitHub不是一个支持论坛,未正确认定为错误的报告将被关闭。
安装
此过程定义了您需要遵循的步骤,无论是通过WordPress安装还是从FTP手动安装。
在WordPress内部
- 访问 '插件 > 添加新插件'
- 搜索自定义永久链接
- 从您的插件页面激活自定义永久链接。
手动
- 将
custom-permalinks
文件夹上传到/wp-content/plugins/
目录 - 通过WordPress的'插件'菜单激活自定义永久链接