Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add custom images sizes to your wordpress theme. See https://since1979.dev/snippet-001-adding-custom-images-sizes/
<?php
/**
* register_thumbnail_sizes.
*
* Register custom images sizes with WordPress,
* These images will be created when an image is uploaded,
* and then stored in the /wp-content/uploads directory.
*
* @see https://since1979.dev/snippet-001-adding-custom-images-sizes/
*
* @uses add_theme_support https://developer.wordpress.org/reference/functions/add_theme_support/
* @uses add_image_size https://developer.wordpress.org/reference/functions/add_image_size/
*/
function register_thumbnail_sizes()
{
// Show the 'featured image' option in the editor.
add_theme_support('post-thumbnails');
// register the actual custom image sizes.
add_image_size('full-page-width', 1000, 9999, true);
add_image_size('half-page-width', 500, 9999, true);
add_image_size('square', 500, 500, true);
}
/**
* Hook: after_setup_theme.
*
* @uses add_action() https://developer.wordpress.org/reference/functions/add_action/
* @uses init https://developer.wordpress.org/reference/hooks/init/
*/
add_action('init', 'register_thumbnail_sizes', 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.