Skip to content

Instantly share code, notes, and snippets.

View swinggraphics's full-sized avatar

Greg Perham swinggraphics

  • Swing Graphics
  • Northampton, MA
View GitHub Profile
@swinggraphics
swinggraphics / thumbnail_minimum_size.php
Last active February 3, 2025 02:52
Use thumbnail settings as minimum size
add_filter( 'wp_constrain_dimensions', 'mcoc_constrain_dimensions', 11, 5 );
function mcoc_constrain_dimensions( $dimensions, $current_width, $current_height, $max_width, $max_height ) {
// Stop if desired size is not post thumbnail
if ( ( $max_width != get_option( 'thumbnail_size_w' ) ) || ( $max_height != get_option( 'thumbnail_size_h' ) ) ) return $dimensions;
// Ensure cropped width is at least post thumbnail width
if ( $dimensions[0] >= $max_width ) return $dimensions;
if ( $current_height > $max_height ) {
return [
$max_width,
$max_width * $current_height / $current_width
@swinggraphics
swinggraphics / redirect_to_canonical.php
Last active February 10, 2025 17:03
Redirect posts to canonical URL when accessed via secondary category URL slugs
<?php
/*
Plugin Name: Redirect to Canonical
Description: Redirect posts to canonical URL when accessed via secondary category URL slugs.
Version: 1.0
Author: Greg Perham
License: GPL2
*/
defined( 'ABSPATH' ) || exit;