H
H
hooli-gun2021-08-16 15:35:25
WordPress
hooli-gun, 2021-08-16 15:35:25

How to insert translation string into php code?

How between span tag

<?php echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale">' . esc_html__( 'Sale!', 'woocommerce' ) . '</span>', $post, $product ); ?>

Insert translation of the word:
<?php pll_e('Скидка'); ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
yarovikov, 2021-08-16
@hooli-gun

<?php echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale">' . pll__( 'Скидка' ) . '</span>', $post, $product ); ?

A
Artem Zolin, 2021-08-16
@artzolin

It is advisable to check before the output that polylang is activated, otherwise you will catch a fatal error

if ( is_plugin_active( 'polylang/polylang.php' ) ) {
  $sale = pll__( 'Скидка' );
} else {
  $sale = esc_html__( 'Sale!', 'woocommerce' );
}

echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale">' . $sale . '</span>', $post, $product );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question