WP_Customize_Image_Control – Default Image not working
-
Hello,
First of all I consider myself a WP noobie still.
So I have added WP_Customize_Image_Control and Custom-Header with nearly 100% success. I am pretty confident that everything is coded right but I must be missing some additional code and hours of searching hasn’t brought up a solution or really anyone besides one person with the same issue.
Issue
If I Customize my WP Header via the Customizer I can change my header and everything works great. However the issue I have is when I click “Hide Image” under Header Image. I then go down and click the suggest image (which is my custom image, great!) once I click it the header image shows in my live preview, however when I click save and publish there is still no header image. To fix this I have to go into Header section under Appearance instead and restore original image. I know this isnt a big deal for us but it can turn out to be a pain for my clients once this theme is done.Any ideas to get around that?
The 2nd issue I have is kind of similar. Its using the exact same principles but its to replace a feature image on the home page. Again it works excellent with changing images, however if I remove the default image and save and publish in the Customize settings, I cant get it back. So my thought is there a piece of code that I am missing that applies to both of these issues? If not does anyone know the WP code used to restore the original header image, so I can use it to restore other images on the page.
Here is my code for the WP_Customize_Image_Control
$wp_customize->add_section('gwenty_images' , array( 'title' => __('Images', 'gwenty'), 'description' => 'Modify Images' )); $wp_customize->add_setting('homepage_image' , array( 'default-image' => 'https://gwenty.com/example/wp-content/themes/gwenty/images/HalfShotbw.jpg', )); $wp_customize->add_control( new WP_Customize_Image_Control($wp_customize, 'homepage_image' , array( 'label' => __('Edit Home Page Image' , 'gwenty'), 'section' => 'gwenty_images', 'settings' => 'homepage_image' ))); and static page HTML code <img src="<?php echo get_theme_mod('homepage_image'); ?> " alt="Home Page Picture" />
Thanks for the help!
Ryan[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
- The topic ‘WP_Customize_Image_Control – Default Image not working’ is closed to new replies.