我无法从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,我得到的只是string(0)“”。
可以帮我吗? 谢谢。
答案 0 :(得分: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)); ?>">