• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2966

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Subscriptions
  • Access
  • Log in

remove_image_size & has_image_size image functions

These new image functions enable you to remove custom image sizes by name conditionally using a custom function and check if your theme has the custom image size by name included.

The 2 New image functions are:

  1. remove_image_size(‘$name’);
  2. has_image_size(‘$name’);

Remove Image Size

add_action('init', 'wpsites_remove_then_add_image_sizes');
function wpsites_remove_then_add_image_sizes() {
	remove_image_size('$name');
	add_image_size( '$name', 300, 150, array( 'left', 'top' ) );
}

Has Image Size

add_action('after_setup_theme', 'wpsites_remove_image_size');
function wpsites_remove_image_size() {
	if(has_image_size('$name')) {
	remove_image_size('$name');
	}
}

Usage

Replace $name with the name of your existing image size or new size

The custom functions would generally go in your child themes functions.php file however you could use them in other files.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Code written by Brad Dalton specialist for Genesis & WooCommerce.

Advertise · WPEngine · Genesis · Log in

  • Account
  • Consulting
  • Post Tags
  • Contact
  • Terms
  • Monthly Membership
  • Yearly Subscriptions
  • Log in