Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Read more text

  • Hi there,

    I have a shortcode in a content template that calls get_the_excerpt. The issue is that the read more text is not translated, but it is translated in WP and GP. Where should I check more?

    Best Regards,
    Peter

  • Hi there,

    Why are you using a shortcode? Why not use the GP dynamic content block to show the excerpt?

  • Because sometimes the output should not be the excerpt but simply a download link.

    function get_indhold_shortcode($atts) {
    	global $post;
    	
    	// Ensure we're in the loop and have a valid post
    	if (!isset($post)) {
    		return '';
    	}
    	
    	// Parse attributes and set default value for altid_fuldt_indhold
    	$atts = shortcode_atts(array(
    		'altid_fuldt_indhold' => false,
    	), $atts);
    	
    	$file = get_field('fil', $post->ID);
    	
    	$loop_content = get_the_content();
    	
    	if ($file || filter_var($atts['altid_fuldt_indhold'], FILTER_VALIDATE_BOOLEAN)){
    	} else{
    		$loop_content = get_the_excerpt();
    	}
    	
    	// Remove HTML comments from the post content
    	$sanitized_content = preg_replace('/<!--(.|\s)*?-->/', '', $loop_content);
    	
    	return wpautop($sanitized_content);
    }
    add_shortcode('indhold', 'get_indhold_shortcode');
  • i see, try changing your code to this:

    function get_indhold_shortcode($atts) {
        global $post;
    
        if (!isset($post)) {
            return '';
        }
    
        $atts = shortcode_atts(array(
            'altid_fuldt_indhold' => false,
        ), $atts);
    
        $file = get_field('fil', $post->ID);
    
        $loop_content = get_the_content();
    
        if ($file || filter_var($atts['altid_fuldt_indhold'], FILTER_VALIDATE_BOOLEAN)) {
            $loop_content = get_the_content();
        } else {
            $loop_content = sprintf(
                '%1$s <a href="%2$s">%3$s</a>',
                get_the_excerpt(),
                get_permalink(),
                __('Read more', 'generatepress')
            );
        }
    
        $sanitized_content = preg_replace('/<!--(.|\s)*?-->/', '', $loop_content);
    
        return wpautop($sanitized_content);
    }
    add_shortcode('indhold', 'get_indhold_shortcode');
    
  • Hi there,

    That gives me two Read more. The new one is correctly translated but the one from the get_the_excerpt function is still there and not translated.

    / Peter

  • Hi there,

    the excerpt_more filter hook allows you to alter the default read more text.
    So with your original code, you could try this to filter in the Read More Text.

    
    function wpdocs_excerpt_more( $more ) {
    	return __('Read more', 'generatepress');
    }
    add_filter( 'excerpt_more', 'wpdocs_excerpt_more' );
    
  • Update: Turns out, the issue was actually staring me in the face the whole time! 😅 I completely overlooked the Read more label option in the settings for the blog in the customizer. Apologies for the unnecessary runaround, and thanks a million for the help anyway! 🙈 Cheers!

  • Glad to hear you found the issue

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