Created
July 10, 2014 23:22
-
-
Save ericnicolaas/37f8bc4ce87913e0d056 to your computer and use it in GitHub Desktop.
Option 2: Retina image control in the Wordpress Customizer
This file contains 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
/** | |
* Retina image control. | |
* | |
* This solution involves creating a new control, implemented as the | |
* Sofa_Customizer_Retina_Image_Control class. | |
* | |
* Using this control, we get a regular image control with a simple | |
* checkbox underneath asking the user whether the image is retina-ready. | |
* This means that the user can just upload a single image and tick a box | |
* if it is correctly sized for retina screens (i.e. it's twice the size | |
* of its regular display). | |
* | |
* Under the hood, the Sofa_Customizer_Retina_Image_Control creates the | |
* non-retina version of the image if the checkbox is ticked. It then | |
* modifies the logo settings that are stored in the database with references | |
* to the retina image's attachment ID, the URL of the non-retina version and | |
* the dimensions of the non-retina version. | |
*/ | |
$wp_customize->add_control( | |
new Sofa_Customizer_Retina_Image_Control( | |
$wp_customize, | |
'logo', | |
array( | |
'settings' => 'logo', | |
'section' => 'header', | |
'label' => __( 'Logo', 'crafted' ), | |
'priority' => 34 | |
) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment