- 状态
- 等待作者
- 相关插件/主题
- Custom Permalinks
- 主题标签
- Compatibility
问题概述
将Custom Permalinks与 WPML 一起使用时,如果目标页面使用了自定义固定链接,指向翻译页面的内部链接可能会指向原始语言页面,而不是翻译页面。
临时解决方法
在继续操作之前,请确保已对您的站点进行完整站点备份。
临时解决方法 – 第一部分
- 打开 …/wp-content/plugins/custom-permalinks/includes/class-custom-permalinks-frontend.php 文件。
- 找到第 165 行。
- 将:
public function wpml_permalink_filter( $permalink, $language_code ) { $custom_permalink = $permalink;
- 替换为:
public function wpml_permalink_filter( $permalink, $language_code ) { $custom_permalink = $permalink; $language_code = apply_filters( 'wpml_current_language', NULL );
临时解决方法 – 第二部分
- 在同一个文件(class-custom-permalinks-frontend.php)中。
- 找到第 913 行。
- 将:
public function custom_page_link( $permalink, $page ) { $custom_permalink = get_post_meta( $page, 'custom_permalink', true ); if ( $custom_permalink ) { $language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $page, 'element_type' => 'page', ) ); $permalink = $this->wpml_permalink_filter( $custom_permalink, $language_code );
- 替换为:
public function custom_page_link( $permalink, $page ) { $custom_permalink = get_post_meta( $page, 'custom_permalink', true ); if ( $custom_permalink ) { $language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $page, 'element_type' => 'page', ) ); $page_translated = apply_filters( 'wpml_object_id', $page, 'page', $language_code ); $custom_translated_permalink = get_post_meta( $page_translated, 'custom_permalink', true ); if ( $custom_translated_permalink ) { $custom_permalink = $custom_translated_permalink; } $permalink = $this->wpml_permalink_filter( $custom_permalink, $language_code );