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

How to add a “data-” attribute to the image tag of native gallery output

Depending on how your Galleria plugin is interacting with the attachment image filters, you should be able to inject your data attribute using the wp_get_attachment_image_attributes filter. Obviously, the attribute would be added for anything using wp_get_attachment_image(), but it will do what you’re asking. /** * Filter attributes for the current gallery image tag. * * … Read more

Having Problem On Getting WP Post Gallery Images URL

As I’ve explained elsewhere, you can modify the image sizes of the get_post_gallery() or get_post_gallery_images() with a simple filter: // Add a filter for full gallery size: add_filter( ‘shortcode_atts_gallery’,’wpse_full_size_gallery’ ); $gallery = get_post_gallery( get_the_ID(), false ); // Remove the filter: remove_filter( ‘shortcode_atts_gallery’,’wpse_full_size_gallery’ ); where: function wpse_full_size_gallery( $out ) { $out[‘size’] = ‘full’; // Edit this … Read more

Crop image to horizontal or vertical by code based on image size

why didn’t use add_image_size( ‘horizontal_img’, 800, 300, true ); add_image_size( ‘vertical_img’, 300, 800, true ); And then $image_hor = wp_get_attachment_image_src($post_id,’horizontal_img’); $image_ver = wp_get_attachment_image_src($post_id,’vertical_img’); when echo $image_hor[0] you will get your desire sized image url. Thanks Musa