0

I'm looking to create a custom function in order to be able to change/load a new image from the "customize" panel (this because I won't be the one who manage the website, so I'm trying to made things as easy as possible).

I used by default the adamos theme (link) and then I started customizing it for my purposes. In functions.php I added the following code:

function gb_theme_customizer( $wp_customize ) {

   $wp_customize->add_section( 'gb_logo_section' , array(
    'title'       => __( 'Gb\'s Logo', 'gb_logo' ),
    'priority'    => 31,
    'description' => 'Upload a new logo for Gb to be displayed above the left menu',
) );

   $wp_customize->add_setting( 
        'gb_logo',
        array(
            'sanitize_callback' => 'gb_sanitize_upload',
        )
    );

$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'gb_logo', array(
    'label'    => __( 'Gb\'s Logo', 'gb_logo' ),
    'section'  => 'gb_logo_section',
    'settings' => 'gb_logo',
) ) );


}
add_action('customize_register', 'gb_theme_customizer');

This was made copying the theme's default function adamos_theme_customizer, that is still above this one (I need both the functions).

To call the function I used the following code:

<!--TEST-->
<?php if ( get_theme_mod('gb_logo') ) : ?>
<div class="test">
<img src="<?php echo get_theme_mod( 'gb_logo' ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
</div>
<?php endif; ?>
<br />

This function actually doesn't work and I don't really know why, because if I try to load images it works (they're loaded, but neither this way are shown). Trying some debugging (see the code below) I found that with get_theme_mod WordPress thinks that gb_logo is a boolean variable.

<div id="test" style="border: 2px solid black"><?php $mods = get_option('gb_logo');
              var_dump($mods);?></div>

Any idea about how to fix this?

tabris963
  • 110
  • 2
  • 14
  • I see one thing that is not correct, but it would only cause a problem with translations: __( 'Gb\'s Logo', 'gb_logo' ) => gb_logo there should be the theme slug. – Axel Feb 27 '15 at 07:26
  • Why do you use this: array('sanitize_callback' => 'gb_sanitize_upload',)? Is gb_sanitize_upload a function? Perhaps try this instead: $wp_customize->add_setting( 'themeslug_logo' ); – Axel Feb 27 '15 at 07:29

0 Answers0