Local WordPress installation doesn’t crop images

For the record since I ended up here when experiencing the same issue on my localhost: In php.ini, Uncomment the line with: extension=php_gd2.dll Restart apache / all services This sorted it out for me (I may have switched a few other services on while I was there, but I believe this is what fixed it!)

ACF Plugin – Random Gallery Image with wp_get_attachment_image()

<?php $images = get_field(‘gallery’); $size=”full”; // (thumbnail, medium, large, full or custom size) $rand = array_rand($images, 1); if( $images ): ?> <?php echo wp_get_attachment_image( $images[$rand][‘ID’], $size ); ?> <?php endif; ?> This code should work. array_rand() return key if second param set to 1 or array with keys if second param > 1

How to add css class to a specific set of images?

You can use the get_image_tag_class filter which passes the attachment ID as an argument: apply_filters(‘get_image_tag_class’, string $class, int $id, string $align, string|array $size) So you can use: function my_image_tag_class($class, $id, $align, $size) { // Logic to check your attachment IDs if($some_logic) { $class .= ‘ no-lazy-loaded’; } return $class; } add_filter(‘get_image_tag_class’,’my_image_tag_class’); If you have an … Read more

Change post featured image on hover

You can add a custom field to you team page, call it “second_picture”, or whatever you want, and add the code <div class=”box”> <div class=”rounded-circle” style=”background-image:url(‘<?php the_post_thumbnail_url(‘full’); ?>’)” id=”staff-pic”> <div class=”second-picture” style=”background-image:url(<?php the_field(‘second_picture’); ?>)”></div> </div> <h3 class=”team-name”><?php the_title(); ?></h3> <p class=”description text-center”><?php echo get_the_content(); ?></p> <div class=”social”><a href=”#”><i class=”fab fa-facebook”></i></a><a href=”#”><i class=”fab fa-twitter”></i></a><a href=”#”><i class=”fab … Read more

How to add image id class?

Shamelessly copied from here: https://letswp.io/add-attachment-id-to-the-class-of-wordpress-images/ add_filter( ‘wp_get_attachment_image_attributes’, ‘add_image_id_class’, 10, 2 ); function add_image_id_class( $attr, $attachment ) { $class_attr = isset( $attr[‘class’] ) ? $attr[‘class’] : ”; $has_class = preg_match( ‘/wpimage\_[0-9]+/’, $class_attr, $matches ); if ( !$has_class ) { $class_attr .= sprintf( ‘ wpimage_%d’, $attachment->ID ); $attr[‘class’] = ltrim( $class_attr ); } return $attr; } This … Read more