Created
January 7, 2015 05:21
-
-
Save designbuildtest/54145bd7b03b3273a6cb to your computer and use it in GitHub Desktop.
Customizer Upload Image / Use as Custom Header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $wp_customize->add_section( 'header_background', array( | |
| 'title' => __( 'Custom Header Image', 'onehundred' ), | |
| 'priority' => 40, | |
| ) ); | |
| $wp_customize->add_setting( 'header_background', array( | |
| 'sanitize_callback' => 'construction_sanitize_file_url', | |
| ) ); | |
| $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'header_background', array( | |
| 'section' => 'header_background', | |
| 'settings' => 'header_background', | |
| 'label' => __( 'Select an Image', 'onehundred' ), | |
| ) ) ); | |
| function construction_sanitize_file_url( $input ) { | |
| $url = ''; | |
| $filetype = wp_check_filetype( $input ); | |
| if ( $filetype["ext"] ) { | |
| $url = esc_url_raw( $input ); | |
| } | |
| return $url; | |
| } | |
| // Add Custom Header | |
| function onehundred_theme_header_css() { | |
| $header_css = get_theme_mod( 'header_background', ''); | |
| if ( ! empty( $header_css ) ) { ?> | |
| <style type="text/css" id="header-css"> | |
| .site-header { background-image: url('<?php echo esc_url( $header_css ); ?>') !important } | |
| </style> | |
| <?php } | |
| } | |
| add_action( 'wp_head', 'onehundred_theme_header_css' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment