问题概述
使用 Divi 主题时,您会注意到,当使用 WPML 翻译包含撇号的按钮文本时,撇号会显示为 HTML 实体。
临时解决方法
这个问题已修复。 更新到最新版本即可在您的站点上解决此问题,因此,只有当您暂时无法更新时,才需要此临时解决方法。
在继续操作之前,请确保对您的站点进行了完整备份。
- 将以下代码添加到主题的 functions.php 文件中:
// WPML workaround for compsupp-7001 add_filter('do_shortcode_tag', 'wpml_compsupp7001_decode_et_pb_button_text', 10, 4); function wpml_compsupp7001_decode_et_pb_button_text($output, $tag, $attr, $m) { if ( class_exists('Sitepress') && 'et_pb_button' === $tag && isset($attr['button_text'])) { // Decode both the ampersand and the apostrophe $output = html_entity_decode($output, ENT_QUOTES, 'UTF-8'); } return $output; }
请注意,如果您使用的是滑块按钮,您将需要使用以下代码行:
if ( class_exists('Sitepress') && 'et_pb_slide' === $tag && isset($attr['button_text'])) {if ( class_exists('Sitepress') && 'et_pb_button' === $tag && isset($attr['button_text'])) {如果您使用的是手风琴项,您将需要使用以下代码行:
if ( class_exists('Sitepress') && 'et_pb_accordion_item' === $tag && isset($attr['title'])) {if ( class_exists('Sitepress') && 'et_pb_button' === $tag && isset($attr['button_text'])) {