[Resolved] Elements not showing in second language | WPML

Home Forums Support [Resolved] Elements not showing in second language | WPML

Home Forums Support Elements not showing in second language | WPML

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #814298
    Pietro

    Hi there,
    I’m having a issue showing a custom header on the second language.
    In the main language i’ve built few header which will load on all posts of a certain category.
    It works fine but in the second language of the post i don’t get the cutom header.

    I saw a solution of placing this code in functions but it doesn’t work for me, actually it doesn’t show the header on both language.

    add_filter( 'generate_header_element_display', 'wpml_generate_header_element_display_filter', 10, 2 );
    function wpml_generate_header_element_display_filter( $display, $post_id ) {
    	$current_language = apply_filters( 'wpml_current_language', null );
    	$element_language = apply_filters( 'wpml_element_language_code', null, array(
    			'element_id'   => $post_id,
    			'element_type' => 'post_gp_elements'
    		)
    	);
    	if ( $current_language != $element_language ) {
    		$display = false;
    	}
    	return $display;
    }

    I’m using your latest version of the theme and all plugins updated.
    WP 5.0.2

    Ps. the posts are only in italian and I’m showing them as translated in english with the WPML option

    Thanks

    #814744
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    We’ll likely need to use a different filter.

    For example, create your Header Element for the second language, and leave the Display Rules empty.

    Then do this:

    add_filter( 'generate_header_element_display', function( $display, $post_id ) {
        if ( is_category( 'your-target-category' ) && 'en_US' === get_locale() && 123 === $post_id ) {
            return true;
        }
    
        return $display;
    }, 10, 2 );

    With the code, you would need to update:

    1. your-target-category with the slug of your category
    2. en_US with the language code you’re targeting
    3. 123 with the ID of the element

    #815306
    Pietro

    Hi Tom,
    thanks for your answer.
    I ended up making a copy of all of the headers for the second language, since i had to create another one in any case.
    It would be great in the future if you could make it possible to query categories / post etc of both languages.

    Thanks again

    #815787
    Tom
    Lead Developer
    Lead Developer

    No problem!

    We’ve had reports that WeGlot handles the translation of the Elements a lot better, in case you ever want to test it.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.