wp_get_attachment_image()
are no longer getting the lazy load treatment. I checked the changelogs and it looks like a previous update changed it. On inspecting the code, there is a commented out line of code in a3-lazy-load/classes/class-a3-lazy-load.php
, line 84: add_filter( 'wp_get_attachment_image_attributes', array( $this, 'get_attachment_image_attributes' ), 200 );
If I uncomment this line of code, all works as expected.
]]>I’m trying to pull in a specific image from the media library onto a page and I’m using the wp_get_attachment_image()
function, but it doesn’t seem to be working.
The image I wish to use has an id of 142, so in the function I’ve done the following:
src="<?php wp_get_attachment_image( 142, 'large', false, [] );?>"
Am I doing this correctly by just adding the ID number in as the 1st parameter? The examples in the docs aren’t particularly informative. I can’t work out why it isn’t working.
Any help would be really appreciated.
]]>wp_get_attachment_image
and the echo
statement.
echo '<a class="image" href="' . get_permalink() . '">' . wp_get_attachment_image( $attachment_id, $original_atts['image_size'] ) . '</a>';
The line is constructed, with the permalink, it is just the image part that is omitted. Thanks.
]]>Is there a way to specify additional sizes for a single image in the library?
For example if a single image used in a single post has an unusual natural width, it is easy to specify that it should be shown in such a that size via the editor, but how would one specify that the additional sizes generated for the srcset should correspond to typical multiples of that such as 1.5x and 2x, instead of/in addition to the sizes that are generated for all other images on the blog.
It kind of sucks, in terms of disk space and srcset html bloat for all the other images, to add the one off sizes to the global list in theme/themename/functions.php. But it also sucks to have web site testing tools complain about client-side shrinking to the one-off size.
]]>??product-image.php
<!– Image Slider –>
<div class=”slider product-responsive”>
<?php foreach ( $attachments as $key => $attachment ) { ?>
<div class=”item-img-slider”>
<div class=”images”>
<?php if ($product->is_on_sale()) : ?>
<?php echo apply_filters(‘woocommerce_sale_flash’, ‘<span class=”onsale”>’.esc_html__( ‘Sale!’, ‘shoppystore’ ).'</span>’, $post, $product); ?>
<?php endif; ?>
” data-rel=”prettyPhoto[product-gallery]” class=”zoom”><?php echo wp_get_attachment_image( $attachment, ‘shop_single’ ); ?>
</div>
</div>
<?php } ?>
</div>
Please help me fix the code. What is wrong with <?php echo wp_get_attachment_image( $attachment, ‘shop_single’ ); ?>
]]>if you can fix this problem for themes that use their own function with the feature image, then i be happy to donate
]]>My idea is uring your plugin to do the retina stuff, but there are loads of images and I dont want to edit all the different phps with images to use ‘rwp_picture’.
Other issue I′m having is that I dont know how to add a class using ‘rwp_picture’ … I′ve tried this:
rwp_picture( $image['ID'], array( "class" => "img-responsive margin-bottom-small wow fadeInUp" ) );
Thank you very much for a great plugin!!!
]]>wp_get_attachment_image
to draw image ftom the uploaded files and I want to attach there an slider wich is made from an plugin. Is there any way to make it real?
]]>I am trying to make a widget which takes post id as input from user and displays images of the specified post in sidebar. wp_get_attachment_url()gets me the url but in the next line wp_get_attachment_image()doesn’t work on same photo=>id. I don’t know where I am going wrong.
Sharing the code of the widget I am tried to put together after going through other wordpress support group posts:
function widget( $args, $instance ) {
echo $args['before_widget'];
$photos = get_children( array('post_parent' => $instance['post'], 'post_type' => 'attachment', 'post_mime_type' => 'image') );
//for getting inline post images only
$post_id=$instance['post'];
$content_post = get_post($post_id);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
if (!empty($photos)) :
//Loop through each attachment..
foreach ($photos as $photo_id => $photo) :
//getting inline post images only
$url = wp_get_attachment_url($photo_id);
$position = strpos($content, $url);
if($position){
echo $post_id;
//working
echo wp_get_attachment_url($photo_id);
//not working
wp_get_attachment_image($photo_id, 'thumbnail') ;
}
endforeach ;
endif ;
]]>In this function I use wp_get_attachment image.
Here wp_get_attachment_image returns the filename of the uploaded image in full resolution, even when I request the “medium”, and width=”1″ height=”1″ and ‘class=”attachment-medium”‘
When I look into the upload-directory, the thumbnail sizes are correctly created.
Could this be a timing problem where the data is not yet written to the database at the time I request it so shortly after the upload?
]]>