Category: Attachments
unitap.io
Untitled Snippet (copy)
Untitled Snippet
Changing the logo on the WordPress login page.
// Zmiana logo na stronie logowania WordPress. add_filter( ‘login_head’, function () { $custom_logo = ‘https://yourimageurl.com’; $logo_width = 200; $logo_height = 84; printf( ‘ ‘, $custom_logo, $logo_width, $logo_height ); }, 990 );Continue reading
Auto convert photos to WEBP (jpg, png)
/** * Konwertuj przesłane obrazy na format WebP * * Ten fragment kodu automatycznie konwertuje przesłane obrazy (JPEG, PNG, GIF) * do formatu WebP w WordPress. Idealny do umieszczenia w pliku functions.php motywu * lub do korzystania z wtyczek takich…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
Add file to media library programmatically
$file = ‘/path/to/file.png’; $filename = basename($file); $upload_file = wp_upload_bits($filename, null, file_get_contents($file)); if (!$upload_file[‘error’]) { $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_parent’ => $parent_post_id, ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, $filename), ‘post_content’ => ”, ‘post_status’ => ‘inherit’ );…Continue reading
Save images as WEBP (copy)
/** * Convert Uploaded Images to WebP Format * * This snippet converts uploaded images (JPEG, PNG, GIF) to WebP format * automatically in WordPress. Ideal for use in a theme’s functions.php file, * or with plugins like Code Snippets…Continue reading
Smush – Original Images
/** * Plugin Name: [Smush] – Original Images * Plugin URI: https://premium.wpmudev.org/ * Description: Displays all original images so they can be deleted. Requires Smush * Author: Panos Lyrakis @ WPMUDEV * Author URI: https://premium.wpmudev.org/ * License: GPLv2 or later…Continue reading