WPML
ステータス
開発者からの返答待ち
関連するプラグイン/テーマ
Custom Permalinks
トピックタグ
Compatibility

問題の概要

WPMLでCustom Permalinksを使用している場合、翻訳先のページがカスタムパーマリンクを使用していると、翻訳されたページへの内部リンクが、翻訳されたページではなく元の言語のページを指すことがあります。

回避策

作業を進める前に、サイトの完全なバックアップを必ず取得してください。

回避策 – パートI


  • …/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 ); 
            

回避策 – パートII


  • 同じファイル(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
    			);
    
            

すべての既知の問題 →