Support » Plugin: Polylang » [Plugin: Polylang] Changing header image according to language

  • Hi there,

    I’m sure there’s a simple solution to this but I can’t find it. My site is bilingual (French-English) and I’d like to display language-specific versions of the header image. I saw that the Featured Image module in the bottom right corner under Page Attributes allows me to set a custom header for specific pages, so I thought I’d use it to set an English header on English pages and vice versa for French. It works, but if Polylang knows of an existing translation for a particular page, it will use that same custom header image for both language versions of the same page. How can I fix that? Thanks…

Viewing 6 replies - 1 through 6 (of 6 total)
  • [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    You can change into your header.php

    The function pll_current_language() give you selected language

    For example, you can have something like that :

    <div id="header">
    <img src="images/header<?php echo pll_current_language(); ?>.jpg" alt="header" />

    If you are with french, image’s name was headerfr.jpg, in english that’s headeren.jpg

    Thanks for the quik reply! This is all new to me, so I may need a little more help to make it work. Would you mind taking a look atthe below ccode from my header.php and tell me exactly where to implement your suggestion? Thanks a lot!

    <body <?php body_class(); ?>>
    <div id="page" class="hfeed">
    	<header id="branding" role="banner">
    				<h1 id="site-title"><span><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></span></h1>
    				<h2 id="site-description"><?php bloginfo( 'description' ); ?></h2>
    				// Check to see if the header image has been removed
    				$header_image = get_header_image();
    				if ( $header_image ) :
    					// Compatibility with versions of WordPress prior to 3.4.
    					if ( function_exists( 'get_custom_header' ) ) {
    						// We need to figure out what the minimum width should be for our featured image.
    						// This result would be the suggested width if the theme were to implement flexible widths.
    						$header_image_width = get_theme_support( 'custom-header', 'width' );
    					} else {
    						$header_image_width = HEADER_IMAGE_WIDTH;
    			<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
    					// The header image
    					// Check if this is a post or page, if it has a thumbnail, and if it's a big one
    					if ( is_singular() && has_post_thumbnail( $post->ID ) &&
    							( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) &&
    							$image[1] >= $header_image_width ) :
    						// Houston, we have a new header image!
    						echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    					else :
    						// Compatibility with versions of WordPress prior to 3.4.
    						if ( function_exists( 'get_custom_header' ) ) {
    							$header_image_width  = get_custom_header()->width;
    							$header_image_height = get_custom_header()->height;
    						} else {
    							$header_image_width  = HEADER_IMAGE_WIDTH;
    							$header_image_height = HEADER_IMAGE_HEIGHT;
    					<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
    				<?php endif; // end check for featured image or standard header ?>
    			<?php endif; // end check for removed header image ?>
    				// Has the text been hidden?
    				if ( 'blank' == get_header_textcolor() ) :
    				<div class="only-search<?php if ( $header_image ) : ?> with-image<?php endif; ?>">
    				<?php get_search_form(); ?>
    				else :
    				<?php get_search_form(); ?>
    			<?php endif; ?>
    			<nav id="access" role="navigation">
    				<h3 class="assistive-text"><?php _e( 'Main menu', 'twentyeleven' ); ?></h3>
    				<?php /* Allow screen readers / text browsers to skip the navigation menu and get right to the good stuff. */ ?>
    				<div class="skip-link"><a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to primary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to primary content', 'twentyeleven' ); ?></a></div>
    				<div class="skip-link"><a class="assistive-text" href="#secondary" title="<?php esc_attr_e( 'Skip to secondary content', 'twentyeleven' ); ?>"><?php _e( 'Skip to secondary content', 'twentyeleven' ); ?></a></div>
    				<?php /* Our navigation menu. If one isn't filled out, wp_nav_menu falls back to wp_page_menu. The menu assigned to the primary location is the one used. If one isn't assigned, the menu with the lowest ID is used. */ ?>
    				<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
    			</nav><!-- #access -->
    	</header><!-- #branding -->
    	<div id="main">

    ok ! You use this function : get_header_image

    Actually, I don’t think that you can use this function with PolyLang.

    Plugin Author Chouby


    You can de-activate the synchronization in Polylang.
    Just add this line:
    define('PLL_SYNC', false);
    either in your wp-config.php or in a new file named pll-config.php (to be placed the wp-content/polylang/ directory – you have to create the directory too). See also at the end of the Polylang documentation.

    Hey thanks VERY MUCH for your help Chouby! I think it works 🙂 Much, much appreciated! Does this have any noticeable side effects to the general behaviour of Polylang?



    Plugin Author Chouby


    The only effect is that all categories, tags and metas associated to posts are no more synchronized between translations (they are still copied though).

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Polylang] Changing header image according to language’ is closed to new replies.