דלג לתוכן דלג לסרגל צד

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

השאר תגובה

אנא הישאר בנושא והיה מכבד כלפי אחרים. אם אתה זקוק לעזרה בנושאים שאינם קשורים לפוסט זה, השתמש בפורום התמיכה שלנו כדי להתחיל צ'אט או לשלוח כרטיס.

אתה יכול להשתמש בתגים אלה:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>