配置仅翻译特定 CPT 的别名
仅翻译特定 CPT 的别名
该插件在设置界面提供了一个翻译文章别名的选项,该选项适用于所有自定义文章类型。

如果您只想翻译某个特定自定义文章类型的别名,而不翻译其他类型,可以通过 hook gatompl:query_variables 来实现:
add_filter(
'gatompl:query_variables',
/**
* @param array<string, mixed> $variables The variables to pass to the query.
* @return array<string, mixed> The variables to pass to the query.
*/
function (
array $variables,
string $querySlug
): array {
if ($querySlug === 'translate-customposts') {
// Define the CPTs for which you want to translate the slug
$translateSlugForCTPs = [
'my-custom-post-type',
];
/** @var string */
$customPostType = $variables['customPostType'];
$variables['updateSlug'] = in_array($customPostType, $translateSlugForCTPs);
}
return $variables;
},
10,
2
);