Site logo

Archived topic

Translating ‘read more’ on custom excerpts, multilingual site

5 replies · Started by Dave on November 28, 2019

Viewing posts 1–6 of 6

I have a multilingual site using Polylang Pro. The site is up-to-date and runs the latest version of GP Premium (1.9.1?).

We use custom excerpts for posts, and I seem to remember we needed to include the following code to get ‘Read More’ to appear:

/* Filter - Remove default 'excerpt more'
	---------------------------------------------------------------------------- */
	function themeprefix_excerpt_more( $more ) {
		return '';
	}
	add_filter('excerpt_more', 'themeprefix_excerpt_more', 21 );

	/* Filter - Add 'read more' to custom excerpt
	---------------------------------------------------------------------------- */
	function themeprefix_get_the_excerpt( $excerpt ) {
		$output = $excerpt;

		$output = sprintf(
			'%1$s <p class="read-more-container"><a class="button read-more" href="%2$s" title="">%3$s</a></p>',
			$excerpt,
			get_permalink(),
			__( 'Read more', 'plugin' )
		);

		return $output;
	}
	add_filter( 'get_the_excerpt', 'themeprefix_get_the_excerpt' );

We’re having trouble getting these strings to translate. I’ve checked that the ‘Read More’ text is blank in the customisr, and also tried adding this code, too.

I’ll include the link for admins, the Spanish can be accessed by visiting /es/

Thanks, Tom!

__( 'Read more', 'gp-premium' ) produces the same result. How would the Polylang function interact with the previous code?

Try this:

add_action( 'init', function() {
    pll_register_string( 'gp-premium-read-more', 'Read more' );
} );

Then replace this:

__( 'Read more', 'gp-premium' )

With this:

pll__( 'Read more' )

Now it should show in your "String Translations" area in the Dashboard.

That’s perfect – thanks so much, Tom!

You're welcome! :)

This archived topic is closed to new replies.