How to get media objects

Have you tried to use get_children() function? Edit: All media attached to any post is treated as children of it. The function wp_get_attachment_image() will only return images. With the function get_children() you’ll be able to get all the media, images or anything else. In the above link, you can find some examples.

wordpress media library shows empty images

Plugins such as Search and Replace can help you to properly fix the URLs in your database. Likewise, consider using backup-and-migration plugins such as BackupBuddy (paid) or Duplicator (free) to properly and more easily move your site (while automatically handling the above search-and-replace operation).

Featured images get shrunken

Hey if you want to add custom image size then add the following code in your function.php file add_image_size( ‘thumb’, 220, 180, true ); and then call featured image in your template like this <?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. the_post_thumbnail(‘thumb’); } ?> … Read more

How can I make all post image uploads have data-width and data-height attributes automatically by default?

Yes you can. See my working fiddle here: http://jsfiddle.net/MonkimoE/0wtgm8a1/ You need to add an id. example: <img class=”img” id=”imageid”….. Delete all atribute “data-width” and “data-height”. because it will added automatically. Add this javascript: (you may change the ‘$’ to ‘jQuery’ if doesn’t work with your theme) <script> var img = document.getElementById(‘imageid’); var width = img.naturalWidth; … Read more

Creating page templates with image placeholders

ACF, which you mentioned, would be the easiest/fastest way to get this done. A post by default has a single thumbnail, no magic option to add another with less work than what ACF does. If the design allows for it, you could also insert the second image straight into content and align it to the … Read more

Add “data-” attribute to image links

while googling about the same issue I came upon your question and a similar question from the WordPress forums. You can control the output of the generated code via the image_send_to_editor filter like this: function filter_image_send_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt) { $html = sprintf(‘<a href=”#” data-rel=”lightbox-0″><img alt=”%2$s” src=”%1$s” /></a>’, esc_attr(esc_url($url)), esc_attr($title)); return … Read more

Is there a way to change wordpress image resize settings?

The file size increase you describe sounds odd. Are you referring to jpegs? Anyway, you can control loss quality for jpegs. Add this to your functions file: add_filter( ‘jpeg_quality’, create_function( ”, ‘return 80;’ ) ); Replacing 80 with whatever percentage you would prefer.

Find unused images?

Is there a reliable up-to-date way to find media that resides on the server but is not used in the WP site? In short: no, not as far as I’m aware. I have found a number of plugins, but all are very old, with lots of negative comments to the effect that they do not … Read more