0

I have some code in my functions.php and when I try to make it localized, I always get it wrong.

Here is the code and I just want to localize the words "Read More":

return '<a href="'. get_permalink( $post->ID ) . 
    '"><span class="readmore">Read More</span></a>';

When I change "Read More" to _e( or __(, I get an error on that line. How do I make it work?

Here is the full function code:

function new_excerpt_more( $more ) {
    global $post;
    return '<a href="'. get_permalink( $post->ID ) . 
        '"><span class="readmore">Read More</span></a>';
} 
add_filter( 'excerpt_more', 'new_excerpt_more' );
0

sprintf() can be used to break the string up so that the translatable string can be isolated from the HTML:

function new_excerpt_more( $more ) {
    return sprintf( '<a href="%1$s"><span class="readmore">%2$s</span></a>',
        get_permalink( get_the_ID() ),
        __( 'Read More', 'your-textdomain' )
    );
} 
add_filter( 'excerpt_more', 'new_excerpt_more' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.