Elementor和WordPress – php特殊字符必须进行转义。

huangapple go评论61阅读模式
英文:

Elementor and WordPress - php special characters must be escaped

问题

我正在尝试将此代码插入到 Elementor > Custom Code 以更改 WooCommerce 中的 Sale Badge 文本

add_filter('woocommerce_sale_flash', 'edit_sale_badge'); function edit_sale_badge() { return '<span class="onsale">TEXT-GOES-HERE</span>'; }

来自此页面:https://pluginsforwp.com/blog/change-sale-badge-woocommerce/ - 但我不知道如何使它工作,有人可以帮助我吗?PHP 可以添加到 Elementor 自定义代码中吗?谢谢!

将代码用 PHP 包裹起来,但出现错误:php 特殊字符必须转义。

英文:

I am trying to insert this code to > Elementor > Custom Code to change the Sale Badge Text in WooCommerce

add_filter(‘woocommerce_sale_flash’, ‘edit_sale_badge’); function edit_sale_badge() { return ‘<span class=”onsale”>TEXT-GOES-HERE</span>’; }

From this page: https://pluginsforwp.com/blog/change-sale-badge-woocommerce/ – But I dont know how to make it work, can anyone help me? Can PHP be added to Elementor custom code? Thanks!

wrap the code with th PHP but getting the error: php special characters must be escaped

答案1

得分: 2

在你的代码中是否用以下方式包装了代码:

<?php和?>

使它看起来像下面这样:

<?php
add_filter('woocommerce_sale_flash', 'edit_sale_badge');
function edit_sale_badge() {
    return 'TEXT-GOES-HERE';
}
?>

在你的链接中,他们将它添加到主题功能中:
functions.php
为什么不也在那里这样做呢?

注意:以下符号之间存在差异:`,´和'。你应该使用最后一个。

英文:

Did you wrap your code with

&lt;?php and ?&gt; 

So that it looks like the following:

&lt;?php
add_filter(&#39;woocommerce_sale_flash&#39;, &#39;edit_sale_badge&#39;);
function edit_sale_badge() {
    return &#39;TEXT-GOES-HERE&#39;;
}
?&gt;

In your Link, they add it to the Themes Functions:
functions.php
Why not do it also there?

Note: there is a difference between the following symbols `, ´ and '. You want to use the last one.

答案2

得分: -1

你不能在Elementor自定义代码区域插入PHP代码。你必须通过子主题的functions.php文件添加。或者你可以通过其他插件添加(2)。

在这里也可以查看:https://elementor.com/help/custom-code-pro/

(2):https://de.wordpress.org/plugins/insert-php-code-snippet/

英文:

You cant insert php in Elementor Custom Code area.. You must add this via functions.php in your child theme. Or you can add this via other plugins (2).

Look also here: https://elementor.com/help/custom-code-pro/

(2): https://de.wordpress.org/plugins/insert-php-code-snippet/

huangapple
  • 本文由 发表于 2023年2月16日 02:01:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75463764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定