【问题标题】:How to add html tag in text domain wordpress如何在文本域wordpress中添加html标签
【发布时间】:2021-11-11 19:16:14
【问题描述】:

如何在“No vendemos en %s”上添加像 span 和 css 类这样的 html 标签来渲染

<span class="something">No vendemos en</span> %s

这是我的php代码

function my_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'No se han encontrado opciones de envío para %s.' :
            $translated_text = __( 'No vendemos en %s', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

【问题讨论】:

  • 把它放在那里。
  • 如果你想打印然后 printf(__( '%s Hello %s world', 'textdomain' ), '', '' );

标签: php html css wordpress woocommerce


【解决方案1】:

使用 php 回显你要添加的 html 的字符串,如果需要,可以在 php 中定义变量:

<?php
$phpValue = 'something';
?>

<html>
<p>Trying to add php info: <?php echo $phpValue; ?></p>
</html>

你也可以对 html 标签和内容做同样的事情:

<?php
 $phpValue = 'something';

echo '<div class="someCSSClass"><p>Trying to add php info:' . $phpValue . '</p></div>';

?>

【讨论】:

  • 在您的具体示例中,它将是完整的 html,带有 span 标签和类,或者您想要的任何其他内容:'No vendemos en %s'
猜你喜欢
  • 1970-01-01
  • 2016-04-02
  • 2022-07-06
  • 1970-01-01
  • 1970-01-01
  • 2021-05-27
  • 2012-12-08
  • 1970-01-01
  • 2017-04-02
相关资源
最近更新 更多