Using the Genesis Featured Image


I decided to write this post because I wanted a way to align my featured image to the right by changing the default class from “alignleft” to “alignright”. I figured it would be simple enough to do. I probably just had to add a filter to a featured image hook or something along those lines.

OMG, I was so wrong.

First thing I realized was that the Genesis Framework doesn’t have a specific filter for the Featured Image. You can add an image in your post and have Genesis pull the first thumb. But when you activate the featured image in the Genesis settings, all you can do is change the size.

[sws_yellow_box box_size=”650″] Yes, I can add a style in my style sheet to override the alignleft class, but my anal coding tells me “NO, there has to be a better way”. [/sws_yellow_box]

First thing I had to remember is that the Genesis Framework is still WordPress. Well duh! But, with all the hooks and filters and functions that are included in the framework, sometimes I forget that I can always go back to the basics.

Genesis doesn’t have a filter that directly affects the featured image on the post but WordPress does!

Sometime the solutions can take so long to get to, but in the end, they’re so simple!

The Solution to using the Genesis Featured Image

First add the image size to your functions.php file.

Quick Explanation: post-image is the reference to the size, 150 is the height and width, TRUE means to crop the image.

Now add the action.

Keep in mind that the featured image is within the post content. So we’re adding our new function to the genesis_post_content hook.

Now the meat!

Here’s a little explanation on what I discovered printf() is. Basically you put in your code with little tags like %s, which just means “string”. There’s also %d which means return an integer. This is almost exactly the same as sprintf(). I’m not sure what the difference is Thanks to Kevin Lloyd, I finally do understand the difference, and it’s used with Genesis, quite often actually so it’s good to start to understand how to use it.

Each %s gets the value from the properties after the quotes IN ORDER. So in the code above, ‘href=”%s”‘ gets the first property which is “get_permalink()” and so on.

The genesis_get_image() function will now return the featured image with the attributes we set at the beginning! You can now manipulate the Genesis Featured Image however you want. Add classes, change alignment, go nuts!!!

Here’s the full code to copy:

Last thing to remember is to disable “Include the Featured Image?” under the Genesis Content Archives settings.
If you know a different way or a better way, please share!

[sws_blue_box box_size=”650″] If you have an image in your post along with a featured image and you’re seeing two images on the homepage before they get into the article, check out this post to fix: Duplicate Featured Image on Post and HomePage Fix[/sws_blue_box]

Resource: I borrowed some code from a wpsmith tutorial on something totally different, thanks!
[sws_divider_padding]

Alternative way to edit the featured image

So I just discovered another way to edit the file, which is so much easier! Here’s the code!

Using TimThumb to Edit the Featured Image Size

Have your image hard cropped so that it’s always the same size.

Focus on what matters!

Focus on what matters!

No more wasting time trying to figure out how to code it all!  Sign up below and I'll share my tips and tricks on how to build websites fast, professionaly, and with minimum code!

You have Successfully Subscribed!