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.
Answer
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
Attribution
Source : Link , Question Author : neil , Answer Author : shamim khan