wordpress - 无法使用 WP_Customize_Image_Cropped_Control 从 get_theme_mod 获取价值
问题描述
我无法从 WP_Customize_Cropped_Image_Control 输出值。
我不明白我做错了什么,我的图像在定制器中挑选和保存很好,但无法输出这个图像。这是我的定制器代码:
$wp_customize->add_setting('mobile_logo', array(
'transport' => 'postMessage',
'sanitize_callback' => 'absint'
));
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'mobile_logo', array(
'label' => esc_html__( 'Mobile Logo', 'my_theme' ),
'height' => 80,
'width' => 120,
'flex-height' => true,
'flex-width' => true,
'settings' => 'mobile_logo',
'section' => 'title_tagline',
)));
我的输出代码:
<?php
$mobile_logo = get_theme_mod( '_mobile_logo' );
?>
<img src="<?php echo esc_url($mobile_logo); ?>">
我尝试了 var_dump $mobile_logo,我得到的只是字符串(0)“”。
你能帮我吗?谢谢。
解决方案
我找到了答案,我应该使用 wp_get_attachment_image_url()。所以答案是:
<?php
$mobile_logo = get_theme_mod( 'mobile_logo' );
?>
<img src="<?php echo esc_url(wp_get_attachment_image_url($mobile_logo)); ?>">
推荐阅读
- c# - 在访问数据库中的两个日期时间选择器之间搜索
- java - 用字母命名包和类
- python-3.x - Spark Structred Streaming Pyspark Sink Csv 不追加
- mysql - 如何在不加入mysql的情况下从另一个表中获取数据
- asp.net-core - 如何使用身份服务器 4 JWT 身份验证和资源所有者密码授权使 jwt 访问令牌无效或撤销?
- php - Getting closest DateTime using strtotime formats
- android - app_process 无法在 /system 中创建文件 - SEED Android Device Rooting Lab
- django - 如何将项目附加到 ListView 中的上下文数据?
- matlab - matlab 中的解析错误问题 - 无法从 .txt 导入数据
- c++ - c++ 连接到 mysql/mariadb 很慢