How to delete resized (cropped) image uploads and prevent future resizing?

A majority of the answers covered how to stop creating future default image sizes but this doesnt account for creating any custom sizes in your theme but here is another solution to add to functions.php: function wpse_240765_unset_images( $sizes ){ unset( $sizes[ ‘thumbnail’ ]); unset( $sizes[ ‘medium’ ]); unset( $sizes[ ‘medium_large’ ] ); unset( $sizes[ ‘large’ … Read more

Masking wp-content/themes/name/images to just images directory using htaccess

Check out the Roots WordPress Theme. They seem to do exactly what you want with the URLs. Here’s a snippet from their roots-htaccess.php file: add_action( ‘generate_rewrite_rules’, ‘roots_add_rewrites’ ); function roots_add_rewrites($content) { $theme_name = next( explode( ‘/themes/’, get_stylesheet_directory() ) ); global $wp_rewrite; $roots_new_non_wp_rules = array( ‘css/(.*)’ => ‘wp-content/themes/’ . $theme_name . ‘/css/$1’, ‘js/(.*)’ => ‘wp-content/themes/’ . … Read more

Remove Dimension from wp_get_attachment_image

Your arguments for both wp_get_attachment_image_url() and wp_get_attachment_image() are in the wrong order – check the linked documentation for details. Additionally, wp_get_attachment_image_url() returns a URL – not an actual image element. Removing the width and height attributes from <img> elements is inadvisable: if the layout of the page is in any way influenced by the size … Read more

Add an alignment option for images

I agree with david-binda – great question! I’ve run in to this problem on a number of occasions and come up with a solution that works pretty well. While I do like the idea of adding a shortcode to insert the image with classes as suggested by pavlos-bizimis I don’t think it really solves the … Read more

Add custom Attachment Display Setting for images

This will add a field in the attachment edit screen for applying a class to the img tag. function IMGattachment_fields($form_fields, $post) { $form_fields[“imageClass”][“label”] = __(“Image Class”); $form_fields[“imageClass”][“value”] = get_post_meta($post->ID, “_imageClass”, true); return $form_fields; } add_filter(“attachment_fields_to_edit”, “IMGattachment_fields”, null, 2); function my_image_attachment_fields_save($post, $attachment) { if ( isset($attachment[‘imageClass’]) ) update_post_meta($post[‘ID’], ‘_imageClass’, $attachment[‘imageClass’]); return $post; } add_filter(“attachment_fields_to_save”, “my_image_attachment_fields_save”, null, … Read more

Set default image link target in Gutenberg image block

This was (finally) fixed to Gutenberg (and will be applicable for both the image and the gallery blocks); and will add an option to WordPress options’ database table. this was done in https://github.com/WordPress/gutenberg/pull/25578 and https://github.com/WordPress/gutenberg/pull/25582 It’ll be added to WordPress 5.6 but it’s already available in the Gutenberg plugin. To link the image to the … Read more

How can you set maximum width for original images?

I was able to solve it using the following code: function my_handle_upload ( $params ) { $filePath = $params[‘file’]; if ( (!is_wp_error($params)) && file_exists($filePath) && in_array($params[‘type’], array(‘image/png’,’image/gif’,’image/jpeg’))) { $quality = 90; list($largeWidth, $largeHeight) = array( get_option( ‘large_size_w’ ), get_option( ‘large_size_h’ ) ); list($oldWidth, $oldHeight) = getimagesize( $filePath ); list($newWidth, $newHeight) = wp_constrain_dimensions( $oldWidth, $oldHeight, $largeWidth, … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş