Limit image resolution on upload

The problem isn’t so much the uploading itself, as that is a network connection between the client and the server. It’s not what’s eating the server’s memory. When WordPress starts ‘cruncing’ the images, that is where PHP comes in and start resizing and cropping the uploaded images. It is before this moment you need to … Read more

wp_get_attachment_image_src and server path

WordPress doesn’t store path of generated sizes anywhere, you need to build it. As suggested by @kraftner in comments, wp_get_attachment_metadata() can be used to obtain some of the pieces you need to build the path. An alternative is image_get_intermediate_size(). The missing piece is the absolute path of upload folder. In theory, that can be retrieved … Read more

How to reference a theme image in a stylesheet?

It depends on your image and stylesheet location. But this is the syntax: .theme-image { background-image: url(‘../images/header-img.jpg’); } The above code is for the structure wp-content – themes – your-theme – images – header-img.jpg – css – style.css You are making the browser come one directory before and search for images directory.

Get attachment/image info in JS

Long story short, you can get info about an attachment by using wp.media.attachment() function. This will give you complete data as long as this attachment is already loaded by another script or an wp.media() popup. If the data is not yet loaded, you can load it using .fetch() method on attachment, which works because it … Read more

Watermarking Images with WordPress with WP_Image_Editor

If you really want to use these classes the only way would be to extend both existing implementations Wp_Image_Editor_Imagick and Wp_Image_Editor_GD. Here’s an approach for the Wp_Image_Editor_GD: namespace WPSE98156; use Wp_Image_Editor_Gd, Wp_Error; class WatermarkImageEditor extends Wp_Image_Editor_Gd { /* * @param resource $stamp (A GD image resource) * * @return bool|WP_Error */ public function stamp_watermark( $stamp … Read more

Is there a simple way to just insert a link to an image (without inserting an image)?

I found a solution based on the code of this page: https://core.trac.wordpress.org/ticket/22180 All attachment files have a post status of ‘inherit’. So first you need to add “inherit” as one of the possible post status to search for. You can use the wp_link_query_args filter to do that. function my_wp_link_query_args( $query ) { if (is_admin()){ $query[‘post_status’] … Read more

Auto Add Image Title,Caption,Alt Text,Description while uploading Images in WordPress

added_post_meta seems like a good time to hook into a new image. Not only is the default meta already set but the function gives you the $post_id along with $meta_value which holds the attachment metadata. From there you can get all the fields and set the ones you want. add_action(‘added_post_meta’, ‘wpse_20151219_after_post_meta’, 10, 4); function wpse_20151219_after_post_meta($meta_id, … Read more

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