- 状态
- 已解决
- 解决于
- WPML Multilingual CMS 4.7.4
- 相关插件/主题
- Elementor
- 主题标签
- Compatibility
问题概述
将Elementor图像轮播小工具与 WPML 结合使用时,即使在媒体库中翻译了说明文字且页面也已翻译,图像的已翻译说明文字也无法在前端显示。
临时解决方法
在继续操作之前,请确保已对您的站点进行完整站点备份。
- 打开您主题的 functions.php 文件。
- 添加以下代码片段:
// WPML Workaround for compsupp-7726
add_filter( 'elementor/frontend/before_render', 'wpml_compsupp7726_filter_imagecarousel_widget');
function wpml_compsupp7726_filter_imagecarousel_widget($element) {
if ( 'image-carousel' !== $element->get_name() ) {
return;
}
$settings = $element->get_settings();
if ( isset( $settings['carousel'] ) && is_array( $settings['carousel'] ) ) {
foreach ( $settings['carousel'] as $key => $value ) {
$post_type = get_post_type( $value['id'] );
if ( ! $post_type ) {
continue;
}
$value['id'] = apply_filters( 'wpml_object_id', $value['id'], $post_type, true );
unset($settings['carousel'][$key]['id']);
$settings['carousel'][$key]['id'] = $value['id'];
}
$element->set_settings( 'carousel', $settings['carousel'] );
}
}