• Hi,

    I’ve been using Polylang to translate our website in 5 languages and it’s working just fine for us, but there is one thing I just can’t figure out how to do.
    I am using the Latest-posts-block for a lot of things, from news to product lists display, and I want to show an excerpt of the posts concerned. At the end I have a “Read more” button, that I don’t know how to translate.

    Here is the code I am using in the latest-posts.php file, found in wp-includes/blocks:

    $post_url = get_permalink( $post_id );
    		$text = get_post( $post_id );
    		$text = $text->post_content;
    		$text = wp_trim_words( $text, 20, '... <a class="wp-block-latest-posts-read-more" href="'.$post_url.'">Read more</a>' );
    		$excerpt = $text;
    				
    		$list_items_markup .= sprintf(
    			'<li class="wp-block-latest-posts-homepage">
    			<a class="wp-block-latest-posts-thumbnail" href="%2$s">%1$s</a><div class="wp-block-latest-posts-extract"><h4>%3$s</h4><p>%4$s</p>',
    			get_the_post_thumbnail( $post_id ),
    			esc_url( get_permalink( $post_id ) ),
    			esc_html( $title ), 
    			$excerpt
    		);

    Right know, Read more is just a plain text, but I’ve tried using things like the following without any success:

    $text = wp_trim_words( $text, 20, '... <a class="wp-block-latest-posts-read-more" href="'.$post_url.'">'.pll_e('Read more').'</a>' );
    and registering the string in my functions.php file.

    Could you help me translating this? It’s not super important but it’ll look better if I could just translate it instead of letting the string in english for all languages.

    Thanks
    Florian

    The page I need help with: [log in to see the link]

The topic ‘Translate “read more” button’ is closed to new replies.