• Regular page previews work fine, but all of the front-pages (translations of the front-page)’s preview links do not display the page.

    I am using “The front page url contains the language code instead of the page name or page id” as a URL modification setting and I think this has something to do with it, but I’m not sure.

Viewing 4 replies - 1 through 4 (of 4 total)
  • +1 for this.

    Preview for translated front pages shows latest post listing instead of the front page.

    Disabling “The front page url contains the language code instead of the page name or page id” option fixes the problem, but it isn’t real “solution”.

    Here is a temporary fix for this issue, which adds post name to the front page preview url, when redirect_lang option is enabled.

    
    /**
     * Fix broken front page preview link in Polylang, when redirect_lang option is enabled.
     *
     * @param $preview_link
     * @param $post
     *
     * @return mixed
     */
    function valu_fix_front_page_preview_link( $preview_link, $post ) {
    
    	// Check that post type is page
    	if ( 'page' !== get_post_type( $post ) ) {
    		return $preview_link;
    	}
    
    	// Check that redirect_lang option is enabled
    	if ( 1 !== PLL()->options['redirect_lang'] ) {
    		return $preview_link;
    	}
    
    	// Get language of the current page
    	$language = PLL()->model->post->get_language( $post->ID );
    
    	// Check that current page is a translation of the default front page
    	if ( $post->ID === $language->page_on_front AND pll_default_language() != $language->slug ) {
    
    		// Get front page link with postname
    		$preview_link_with_postname = esc_url( trailingslashit( get_permalink( $post->ID ) . $post->post_name ) );
    
    		// Apply new preview link
    		$preview_link = str_replace( PLL()->links_model->home_url( $language ), $preview_link_with_postname, $preview_link );
    
    	}
    
    	return $preview_link;
    
    }
    
    add_filter( 'preview_post_link', 'valu_fix_front_page_preview_link', 30, 2 );
    
    Thread Starter mantarays

    (@mantarays)

    Thanks Mikko! Your fix worked for me.

    • This reply was modified 8 years, 8 months ago by mantarays.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Preview Front Page broken?’ is closed to new replies.