Forked from zeropointdevelopment/code-snippet-1.php
Last active
August 10, 2017 05:12
-
-
Save DeveloperWil/42bf52b56fc1f58cd48e3351155daffd to your computer and use it in GitHub Desktop.
[WordPress] Code from our blog post Adding Custom Image Sizes to WordPress 3.5 Media Manager - https://zeropointdevelopment.com/adding-custom-image-sizes-to-wordpress-3-5-media-manager/
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
// Add new image sizes | |
function zpd_insert_custom_image_sizes( $image_sizes ) { | |
// get the custom image sizes | |
global $_wp_additional_image_sizes; | |
// if there are none, just return the built-in sizes | |
if ( empty( $_wp_additional_image_sizes ) ) | |
return $image_sizes; | |
// add all the custom sizes to the built-in sizes | |
foreach ( $_wp_additional_image_sizes as $id => $data ) { | |
// take the size ID (e.g., 'my-name'), replace hyphens with spaces, | |
// and capitalise the first letter of each word | |
if ( !isset($image_sizes[$id]) ) | |
$image_sizes[$id] = ucfirst( str_replace( '-', ' ', $id ) ); | |
} | |
return $image_sizes; | |
} | |
function zpd_custom_image_setup () { | |
add_theme_support( 'post-thumbnails' ); | |
add_image_size('Mini Square', 70, 70, TRUE); | |
add_image_size('Square', 100, 100, TRUE); | |
add_image_size('Featured Tabs', 150, 225, TRUE); | |
add_image_size('Featured', 640, 220, TRUE); | |
add_filter( 'image_size_names_choose', 'zps_insert_custom_image_sizes' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment