Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Last active January 2, 2020 13:02
Show Gist options
  • Save vanaf1979/ecf9c744c5b0f60a0a7438af63aa3954 to your computer and use it in GitHub Desktop.
Save vanaf1979/ecf9c744c5b0f60a0a7438af63aa3954 to your computer and use it in GitHub Desktop.
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