Community Forums › Forums › Archived Forums › General Discussion › Featured image not being hard cropped
- This topic has 5 replies, 2 voices, and was last updated 7 years, 11 months ago by alistairmckenzie.
-
AuthorPosts
-
January 18, 2017 at 4:18 am #199596alistairmckenzieMember
Hi,
I'm displaying some latest news posts on the homepage however the featured images are not being hard cropped for some reason.
I have this in my functions:
add_image_size( 'home-news', 280, 280, TRUE );
And this is what I use to pull in the latest posts in my front-page.php
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); add_action( 'genesis_entry_header', 'custom_featured_image', 5 ); function custom_featured_image() { $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'home-news' ), 'attr' => array( 'class' => 'alignnone post-image' ) ) ); printf( '<a href="%s" title="%s">%s </a>', get_permalink(), the_title_attribute( 'echo=0' ), $img ); }
Can anyone see why it is being soft cropped instead of hard cropped please?
January 18, 2017 at 6:24 am #199598Victor FontModeratorWhen did you add the code to hard crop it? You may need to regenerate thumbnails.
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?January 18, 2017 at 8:04 am #199605alistairmckenzieMemberHi Victor, I've already tried regenerating the thumbnails but that unfortunately didn't work 🙁
January 18, 2017 at 8:44 am #199606Victor FontModeratorAre the cropped images showing up in the image directory?
Regards,
Victor
https://victorfont.com/
Call us toll free: 844-VIC-FONT (842-3668)
Have you requested your free website audit yet?January 18, 2017 at 10:49 am #199616alistairmckenzieMemberYes they are being generated in the image directory at the 280px 280px size. I think it is a problem with the function I've used to show the image because this is the output on the page:
<img width="767" height="850" src="http://thewebsiteaddress.co.uk/mytheme/wp-content/uploads/2016/10/theimage.jpg" class="alignnone post-image" alt="" srcset="thewebsiteaddress.co.uk/mytheme/wp-content/uploads/2016/10/theimage.jpg 767w, http://thewebsiteaddress.co.uk/mytheme/wp-content/uploads/2016/10/theimage-271x300.jpg 271w" sizes="(max-width: 767px) 100vw, 767px">
So it appears that this is where it is going wrong and I need to correct the function in my original posts that outputs the image to the page. It obviously isn't using the 'home-news' size.
January 18, 2017 at 3:29 pm #199629alistairmckenzieMemberI think I've been overthinking this and I've managed to achieve the result that I wanted.
For other peoples reference I just changed:
function custom_featured_image() { $img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'home-news' ), 'attr' => array( 'class' => 'alignnone post-image' ) ) ); printf( '<a href="%s" title="%s">%s </a>', get_permalink(), the_title_attribute( 'echo=0' ), $img ); }
To a much simpler version, this:
function custom_featured_image() { echo '<div class="news-featured-image">'; the_post_thumbnail('home-news'); echo '</div>'; }
The downside is that this way the image doesn't link to the post but I don't require that anymore.
It would be nice if someone could help amend the above to include the 'alt' tag because that is missing?
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.