Created
August 14, 2015 13:12
-
-
Save thadallender/8427dd4bbbf3713eea8b to your computer and use it in GitHub Desktop.
Filter to Sell Media that adds a new image size for a new image aspect ratio used in Sell Media archives and shortcodes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Sell Media Image Size Filter | |
* Plugin URI: https://graphpaperpress.com/plugins/sell-media/ | |
* Description: Filter to Sell Media that adds a new image size for a new image aspect ratio used in Sell Media archives and shortcodes | |
* Version: 1.0.0 | |
* Author: Thad Allender | |
* Author URI: https://graphpaperpress.com | |
* Author Email: [email protected] | |
* Text Domain: sell_media | |
* Domain Path: languages | |
* License: GPL2 | |
*/ | |
/** | |
* Filters the size of thumbnail in Sell Media | |
* | |
* By default, Sell Media use the "Medium" size image. Depending on your unique situation, | |
* you might want to use a different size. While you can control the size of images | |
* by visiting the Settings -> Media page in WordPress, changing this might effect areas | |
* in your website that you would rather keep "as is." By using the "sell_media_thumbnail" filter, | |
* we can tell Sell Media to use a different image size called "custom-thumbnail" | |
* on archives and in shortcodes. | |
*/ | |
function sell_media_new_thumbnail_size(){ | |
return 'custom-thumbnail'; | |
} | |
add_filter( 'sell_media_thumbnail', 'sell_media_new_thumbnail_size' ); | |
/** | |
* Adds new image size to WordPress | |
* | |
* You can change 600 and 600 below to be any size that you want. | |
* As is, the new thumbnail sizes will be cropped into 600px x 600px square. | |
* The last parameter "true" in the add_image_size function tells WordPress | |
* to either crop the image to exactly 600 x 600 or "false" for only cropping | |
* the longest side and keeping the image proportional. To recrop previously | |
* uploaded images to this new size, you need to install | |
* the Regenerate Thumbnails plugin (free at WordPress.org). | |
*/ | |
function sell_media_add_image_size(){ | |
add_image_size( 'custom-thumbnail', 600, 600, true ); | |
} | |
add_action( 'after_setup_theme', 'sell_media_add_image_size' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment