Skip to content

Instantly share code, notes, and snippets.

@mrwweb
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrwweb/56edda993e0b7062c7af to your computer and use it in GitHub Desktop.
Save mrwweb/56edda993e0b7062c7af to your computer and use it in GitHub Desktop.
Example of fpw_image_size filter in Feature a Page Widget 2.0. By default, Feature a Page Widget registers three sizes, one for each layout: fpw_big, fpw_square, fpw_banner. NOTE: To produce consistent image sizes and a good widget layout, CSS rules like max-width may at times affect the image's apparent size on the front end.
<?php
/**
* replace one of the widget image sizes
*
* examples replaces the banner layout's image with the 'large' size image from Settings > Media
*
* If you replacing $size with a custom image size, you must register that separately with add_image_size()
*
* @param $size string slug of registered image size
* @return string|array slug of registered image size or "array( width, height )" (not recommended)
*/
function fpw_change_image_size( $size ) {
// check if image uses the "banner" layout image size
if( $size === 'fpw_banner' ) {
$size = 'large';
}
return $size;
}
add_filter( 'fpw_image_size', 'fpw_change_image_size' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment