Localization inside shortcode not working
I use a shortcode that retrieves the url of woocommerce products and builds a link:
function woo_url_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' = null,
), $atts, 'bartag' );
$html = '';
if( intval( $atts['id'] ) 0 function_exists( 'wc_get_product' ) ) {
$_product = wc_get_product( $atts['id'] );
$html = $_product-get_permalink();
}
$text = 'Some text';
return 'p class=woo-bookinga href='.$html.''.$text.'/a/p';
}
Works fine. But now I need the text translated like this:
esc_html_e( 'Some text', 'generatepress-child' );
So, the code would be:
function woo_url_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' = null,
), $atts, 'bartag' );
$html = '';
if( intval( $atts['id'] ) 0 function_exists( 'wc_get_product' ) ) {
$_product = wc_get_product( $atts['id'] );
$html = $_product-get_permalink();
}
return 'p class=woo-bookinga href='.$html.''.esc_html_e( 'Some text', 'generatepress-child' ).'/a/p';
}
Language files are there and working. But not with this shortcode. The string is translated but appears at the top of the page and is repeated several times. What exactly am I missing, and how can I fix this?
Thank you!