Disable Thumbnail Image Sizes

add_filter( ‘intermediate_image_sizes_advanced’, function( $sizes ) { // Disable specific thumbnail sizes, uncomment the ones you want to disable. // unset( $sizes[‘thumbnail’] ); // 150px x 150px // unset( $sizes[‘medium’] ); // 300px x 300px // unset( $sizes[‘medium_large’] ); // 768px…Continue reading

Add Auto Sizes to Lazy Loaded images

add_filter( ‘wp_get_attachment_image_attributes’, function( $attr ) { if ( ! isset( $attr[‘loading’] ) || ‘lazy’ !== $attr[‘loading’] || ! isset( $attr[‘sizes’] ) ) { return $attr; } // Skip if attribute was already added. if ( false !== strpos( $attr[‘sizes’], ‘auto,’…Continue reading

Allow Contributors to Upload Images

add_filter( ‘user_has_cap’, function ( $allcaps, $caps, $args, $user ) { if ( in_array( ‘contributor’, $user->roles ) && empty( $caps[‘upload_files’] ) ) { $allcaps[‘upload_files’] = true; } return $allcaps; }, 10, 4 );Continue reading

Limit Uploaded Image Size

add_filter( ‘wp_handle_upload’, function ( $file ) { $max_width = 1920; $max_height = 1920; // Check if the file is an image. $mime_type = mime_content_type( $file[‘file’] ); if ( strpos( $mime_type, ‘image’ ) === false ) { return $file; } //…Continue reading

Add Media File Size Column

add_filter( ‘manage_upload_columns’, function ( $columns ) { $columns [‘file_size’] = esc_html__( ‘File size’ ); return $columns; } ); add_action( ‘manage_media_custom_column’, function ( $column_name, $media_item ) { if ( ‘file_size’ !== $column_name || ! wp_attachment_is_image( $media_item ) ) { return; }…Continue reading

Add Featured Image Column

add_filter( ‘manage_posts_columns’, function ( $columns ) { // You can change this to any other position by changing ‘title’ to the name of the column you want to put it after. $move_after = ‘title’; $move_after_key = array_search( $move_after, array_keys( $columns…Continue reading

Remove Query Strings From Static Files

function wpcode_snippet_remove_query_strings_split( $src ) { $output = preg_split( “/(&ver|\?ver)/”, $src ); return $output ? $output[0] : ”; } add_action( ‘init’, function () { if ( ! is_admin() ) { add_filter( ‘script_loader_src’, ‘wpcode_snippet_remove_query_strings_split’, 15 ); add_filter( ‘style_loader_src’, ‘wpcode_snippet_remove_query_strings_split’, 15 ); }…Continue reading

Add default ALT to avatar/Gravatar Images

add_filter( ‘pre_get_avatar_data’, function ( $atts ) { if ( empty( $atts[‘alt’] ) ) { if ( have_comments() ) { $author = get_comment_author(); } else { $author = get_the_author_meta( ‘display_name’ ); } $alt = sprintf( ‘Avatar for %s’, $author ); $atts[‘alt’]…Continue reading