Change image link: wp_get_attachment_link

I think I’ve answered my own question sort of…. As I was using a child theme of Hybrid I activated the cleaner gallery extension in the functions.php file: add_theme_support( ‘cleaner-gallery’ ); Then, based on the topic here I created my own filter: add_filter( ‘cleaner_gallery_image’, ‘my_gallery_image’, 10, 4 ); function my_gallery_image( $image, $id, $attr, $instance ) … Read more

How to remove title attribute from gallery links and images

I’ve found a solution : // Remove <img> title attribute in // http://wordpress.org/support/topic/wp_get_attachment_image_attributes-filter-not-working function remove_img_title($atts) { unset($atts[‘title’]); return $atts; } add_filter(‘wp_get_attachment_image_attributes’,’remove_img_title’, 10, 4); // remove title attribute from <a> title attribute in // modified from this post : http://oikos.org.uk/2011/09/tech-notes-using-resized-images-in-wordpress-galleries-and-lightboxes/ function ah_get_attachment_link_filter( $content ) { $new_content = preg_replace(‘/title=\'(.*?)\”https://wordpress.stackexchange.com/”, ”, $content ); return $new_content; } add_filter(‘wp_get_attachment_link’, ‘ah_get_attachment_link_filter’, … Read more

Define WordPress image size in img tag

How about PHP Function getimagesize() <? $sImageurl = of_get_option(‘slideshow_1’); list($iWidthinpx, $iHeightinpx) = getimagesize($sImageurl); echo ‘<img src=”‘ . $sImageurl . ‘” width=”‘ . $iWidthinpx. ‘” height=”‘ . $iHeightinpx. ‘” alt=”#”/>’; ?> or if you know the attachment id instead of the attachment url you could use <? $aImagedata = wp_get_attachment_image_src($iAttachmentid, ‘my-image-size’, false); list($sImageurl, $iWidthinpx, $iHeightinpx) = … Read more

get post attachments of a particular size

The image attachment type is stored in the postmeta table in the _wp_attachment_metadata meta key. The data is serialized, so it can’t be filtered on. But you could use a meta_query in your query: $images = get_posts( array( ‘post_type’ => ‘attachment’, ‘orderby’ => ‘rand’, ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘_wp_attachment_metadata’, ‘value’ … Read more

When inserting images into posts auto add a wrapping div

I think it is a better idea, if you filter the output, the the_content and add the div on all images. It is better for feature, if you will remove this markup, it is not inside the database. add_filter( ‘the_content’, ‘fb_add_div_to_img’ ); function ( $content ) { // find img and add markup return $content; … Read more

Setting up a gallery with images and a zip download

You can use the built-in functionality to solve this: The WordPress Gallery. Each post and page (and normally custom types) can have files of all kind attached to it. You upload them through the Add Media button, and have the option to make a Gallery with the images attached to this post/page or with other … Read more

How can I serve different images depending on screen size with wordpress

add_image_size does change the actual size of the image file. What I hava tried: function odevice_image_sizes() { add_image_size( ‘iphone-size’, 300, 100, true );//OF course the dimensions are not correct… add_image_size( ‘tablet-size’, 600, 300, true ); } function show_odevice_at_img_select($sizes) { $sizes[‘iphone-size’] = __( ‘Image size for iphone’ ); $sizes[‘tablet-size’] = __( ‘image size for tablet’ ); … Read more

Debugging upload problem: What part of WP does actual image-resizing?

You can add a filter to wp_image_editors and see what editor is in use (GD or Imagick). In a past project I’ve extended the resize routines on both GD, and Imagick, and the methods responsible for resize are WP_Image_Editor_Imagick->crop() and WP_Image_Editor_GD->_resize(). Note that WP_Image_Editor_GD->resize() is just a wrapper. The process it’s run on ajax, but … Read more

Alter media caption/description conflict in WordPress?

I wonder if this will work for you: add_action( ‘add_attachment’, function( $attachment_id ){ $a = get_post( $attachment_id ); if ( is_object( $a ) && ‘image’ === substr( $a->post_mime_type, 0, 5 ) ) wp_insert_attachment( array( ‘ID’ => $a->ID, ‘post_excerpt’ => $a->post_content ) ); }); or with less queries: add_action( ‘add_attachment’, function( $attachment_id ){ global $wpdb; if( … Read more