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

WP SITES

2784

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Consultation
  • Full 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

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags