Saltar al contenido Saltar a la barra lateral

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

Dejar una respuesta

Por favor, mantente en el tema y sé respetuoso con los demás. Si necesitas ayuda con problemas no relacionados con esta publicación, utiliza nuestro Foro de Soporte para iniciar un chat o enviar un ticket.

Puedes usar estas etiquetas:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>