1

Hello every one i am facing one issue in adding logo option in my theme panel of wordpress i am using this code

function logo_display()
{
    ?>
        <input type="file" name="logo" /> 
        <?php echo get_option('logo'); ?>
   <?php
}
function handle_logo_upload()
{
    if(!empty($_FILES["demo-file"]["tmp_name"]))
    {
        $urls = wp_handle_upload($_FILES["logo"], array('test_form' => FALSE));
        $temp = $urls["url"];
       return $temp;   
    }  
    return $option;
}
function display_theme_panel_fields()
{
    add_settings_section("section", "All Settings", null, "theme-options");
    add_settings_field("logo", "Logo", "logo_display", "theme-options", "section");  
    register_setting("section", "logo", "handle_logo_upload");
}
add_action("admin_init", "display_theme_panel_fields");

The issue is its not saving logo and also not displaying it in admin as well. I have tried this 10 times with different ways but this code is not working. Please look in this code and help me in it please.

1

if you use wordpress customizer then try this code

public static function register ( $wp_customize ) {
    // Logo upload
    $wp_customize->add_section( 'bia_logo_section' , array(
        'title'       => __( 'Site Logo', 'bia' ),
        'priority'    => 30,
        'description' => 'Upload a logo to replace the default site name and description in the header',
    ) );

    $wp_customize->add_setting( 'bia_logo', array(
        'sanitize_callback' => 'esc_url_raw',
    ) );

    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'bia_logo', array(
        'label'    => __( 'Site Logo', 'bia' ),
        'section'  => 'bia_logo_section',
        'settings' => 'bia_logo',
    ) ) );
}

i think you can also try redux framework for admin panel option

| improve this answer | |
  • HI buddy i am making it with custom code for a practice purpose so. now only one issue which is left in my above code is after saving a logo if i save it again it goes blank and replace the current updated logo. i am looking for its solution only now. – neil Sep 1 '16 at 6:43
  • Hi i think you can check this video youtube.com/watch?v=nvsK0cTH0So – shamim khan Sep 1 '16 at 7:42
2

Since version 4.5 the Theme Logo is a standard feature of WordPress. You can simply add the following code to your functions.php:

function wpse237461_theme_logo() {
    add_theme_support( 'custom-logo', array(
        'height'      => 100,
        'width'       => 400,
        'flex-width' => true ) );
    }
add_action( 'after_setup_theme', 'wpse237461_theme_logo' );

Now you can change the logo in the theme customizer and you can add it to your theme with the_custom_logo(). No need to handle files and options yourself.

| improve this answer | |
  • HI i have done this and code is working fine. only issue which is comming in it now is if person again save the logo without adding image it show blank option. – neil Sep 1 '16 at 3:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.