将 HTML 链接添加到 PHP 消息数组



在Woocommerce登录模块中,有一段文本需要编辑,并在消息中放置了一个注册链接。但是,如果我只是在链接周围添加 HTML 标签,那么代码就会显示在文本中,而不是作为链接。

这是表单登录.php文件中的原始代码

'message'  => esc_html__( 'If you have shopped with us before, please enter your details below. If you are a new customer, please proceed to the Billing section.', 'woocommerce' ),

这就是我将其更改为包含注册和链接的方式:

'message'  => esc_html__( 'If you have shopped with us before, please enter your details below. If you are a new customer, please' . '<a href="#login" class="register-text">Register</a>' . ' to proceed.', 'woocommerce' ),

我也尝试了以下内容,但它破坏了网站,所以不是一个选择:

'message'  => esc_html__( 'If you have shopped with us before, please enter your details below. If you are a new customer, please' . '<a href="#login" class="register-text">Register</a>' . ' to proceed.', 'woocommerce' ),

我只需要"注册"一词成为带有颜色和悬停的特定类的链接(在 CSS 中创建(。请问我该怎么做?

esc_html 转义你的HTML代码,所以<a href="#login" class="register-text">Register</a>变得&lt;a href=&quot;#login&quot; class=&quot;register-text&quot;&gt;Register&lt;/a&gt;.

您需要删除 esc_html(( 函数。

(不过要小心,因为如果使用动态内容,提供未转义的 HTML 可能会很危险 了解更多...

感谢内森·阿诺德。我尝试了几次,但我终于做对了。最终代码如下所示:

'message'  => __( 'If you have shopped with us before, please enter your details below. If you are a new customer, please' . '<a href="#login" class="register-text"> Register</a>' . ' to proceed.', 'woocommerce' ),

我不明白为什么"__"需要在那里,但是如果我删除它,那么没有任何效果,所以我把它留了下来。

最新更新