Chuyển đến nội dung Chuyển đến thanh bên

Waiting for author

Topic Tags: Compatibility

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
    			);
    
            

Để lại trả lời

Vui lòng giữ đúng chủ đề và tôn trọng người khác. Nếu bạn cần trợ giúp với các vấn đề không liên quan đến bài đăng này, hãy sử dụng Diễn đàn Hỗ trợ của chúng tôi để bắt đầu trò chuyện hoặc gửi vé hỗ trợ.

Bạn có thể sử dụng các thẻ này:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>