Created
April 6, 2022 08:00
-
-
Save LucaRosaldi/71a1987d3cbbc45e165a767447f09f71 to your computer and use it in GitHub Desktop.
WP: add custom image sizes
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
<?php | |
/** | |
* Add custom image sizes. | |
* | |
* @hook after_setup_theme | |
* | |
* @return void | |
*/ | |
function my_theme_add_custom_image_sizes() : void | |
{ | |
add_image_size( 'my-theme-thumbnail', 600, 450, true ); | |
add_image_size( 'my-theme-medium', 900, 675, true ); | |
add_image_size( 'my-theme-large', 1200, 900, true ); | |
} | |
add_action( 'after_setup_theme', 'my_theme_add_custom_image_sizes' ); | |
/** | |
* Make custom image sizes selectable | |
* | |
* @hook image_size_names_choose | |
* | |
* @param array $sizes | |
* @return array | |
*/ | |
function my_theme_select_custom_image_sizes( array $sizes ) : array | |
{ | |
return array_merge( $sizes, [ | |
'my-theme-thumbnail' => __( 'Card Image' ), | |
'my-theme-medium' => __( 'Section Image' ), | |
'my-theme-large' => __( 'Background Image' ) | |
]); | |
} | |
add_filter( 'image_size_names_choose', 'my_theme_select_custom_image_sizes' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment