Waiting for author
Overview of the issue
When using Custom Permalinks with WPML, internal links to translated pages may point to the original-language page instead of the translated page when the target page uses a custom permalink.
Workaround
Please, make sure of having a full site backup of your site before proceeding.
Workaround – Part I
- Open the …/wp-content/plugins/custom-permalinks/includes/class-custom-permalinks-frontend.php file.
- Look for line 165.
- Replace:
public function wpml_permalink_filter( $permalink, $language_code ) { $custom_permalink = $permalink; - With:
public function wpml_permalink_filter( $permalink, $language_code ) { $custom_permalink = $permalink; $language_code = apply_filters( 'wpml_current_language', NULL );
Workaround – Part II
- In the same file (class-custom-permalinks-frontend.php).
- Look for line 913.
- Replace:
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 ); - With:
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 );