Media Upload Folder – how to manage

A simple answer is that you can remove 2 unused sizes by enter 0 for their width or height. For example, you need only the small thumbnail 150×150 and full-sized image, so enter 0 for width and height of Medium and Large sizez.

How to find attachment by it’s name?

You have to write custom code to get the attachment id and post_parent by name/ slug or filename(if it has not been changed during the uploading of files). Put the below code in your theme’s functions.php file if( ! ( function_exists( ‘wp_get_attachment_by_post_name’ ) ) ) { function wp_get_attachment_by_post_name( $post_name ) { $args = array( ‘posts_per_page’ … Read more

How to insert images into posts without using Add Media dialog

The WordPress default media management system is pretty good and far better than what you want. However, you can use the Advanced Custom Fields to add image upload boxes in your post editor page. Once the image is uploaded, you can display it in the editor using a shortcode [acf field=”{$field_name}”]. Check out ACF Documentation … Read more

Rename files on upload

no need to use a custom table, use an option, and the add_attachment hook: function wpa59168_rename_attachment( $post_ID ) { $post = get_post( $post_ID ); $file = get_attached_file( $post_ID ); $path = pathinfo( $file ); $count = get_option( ‘wpa59168_counter’, 1 ); // change to $new_name = $count; if you want just the count as filename $new_name … Read more

Maintaining image color and quality when uploading using custom sizes

Use the jpeg_quality and wp_editor_set_quality filters to set the quality of resized images: add_filter( ‘wp_editor_set_quality’, ‘wpse246186_image_quality’ ); add_filter( ‘jpeg_quality’, ‘wpse246186_image_quality’ ); function wpse246186_image_quality( $quality ) { return 100; // 0 – 100% quality } I have not been able to reproduce the issue reported; the original PNG image looks the same as the thumbnails. Tested … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)