WPML
状态
已解决

问题概述

当 URL 在一种语言中无效时,WPML 会检查该 URL 是否在另一种语言中有效。如果确认有效,WPML 会将访问者重定向到包含语言信息的正确 URL。

但是,此行为可能会导致自定义重写规则出现问题。

临时解决方法

WPML 在此重定向上提供了 wpml_is_redirected 过滤器。以下是使用示例:

/**
* This will prevent redirection in the secondary language for the custom rule:
* '^products/([A-Za-z0-9-]+)/?' => 'index.php?pagename=new-sample&type=$matches[1]'
*/
function wpmlcore_4704_block_redirect( $redirect, $post_id, $q ) {
// Decide on which condition we should prevent the redirection
if ( isset( $q->query_vars['pagename'] ) && 'sample-page' === $q->query_vars['pagename'] ) {
return false;
}

return $redirect;
}
add_filter( 'wpml_is_redirected', 'wpmlcore_4704_block_redirect', 10, 3 );

所有已知问题 →