Community Forums › Forums › Archived Forums › General Discussion › "Featured Image" for Homepage when Shared
- This topic has 10 replies, 3 voices, and was last updated 10 years, 3 months ago by
Carlo.
-
AuthorPosts
-
January 8, 2015 at 1:17 pm #136410
Kary
MemberHi all...not seeing anything that answers this question. Is there a way to set a specific image (like the logo) that will shared when the main site's URL is shared via social media.
I know there is a way to do this in the meta tags, but that designates a specific image for the entire site. I just want to be able to set a pre-determined image for the homepage. Since it is a page that is dynamically created, sometimes (often times) the image that gets pulled by sites like Facebook isn't always the one you want.
January 9, 2015 at 4:13 pm #136791Shawberry Themes
MemberHello Kary!
I have been successful doing this by going to the Home Page and designating a featured image. Have you tried that?
Shawna B.
http://www.busymomibeeblogdesigns.comJanuary 10, 2015 at 5:28 am #136840Carlo
MemberYou can have the meta tags only show on the front page. You'd use something like this:
add_action( 'wp_head', function() { if ( is_front_page() ) echo '<meta name="" content="">'; } );
January 12, 2015 at 8:10 am #137169Kary
MemberHi Shawna, it would work perfectly except my theme doesn't actually have a home page that I created. So I would have to do that somehow on the template file.
Thanks Carlo, someone else pointed me to GitHub snippet. https://gist.github.com/callingmedic911/22fa7f8071f69232d640
It is a similar idea to your function.I know little about writing a function code that won't break the theme. So I inserted the one from GitHub (Below) using Dreamweaver and received an error and of course deleted before saving. Something was wrong with that code. So I'll see if I can get your's to work. Thanks so much.
medic_home_og() { if ( is_home() ) echo '<meta property="og:image" content="http://link/to/your/og/image/file" />'; } add_action( 'wp_head', 'medic_home_og', 5);
January 12, 2015 at 8:23 am #137172Kary
MemberOkay...not working. I believe its because the theme I'm using (Parallax Pro) you don't actually set a static homepage for the "home page." You simply start filling in the widgets and the home template becomes active.
The code
if ( is_front_page() )
is looking for a static homepage that I would have set in my WP admin area.Does anyone have an idea as to how to get this function to work on a theme like the one I'm using?
January 12, 2015 at 8:29 am #137173Kary
MemberIt doesn't appear
if ( is_home() )
works either. Neither of these add an image to my og: image meta tag. I checked in two ways. I physically looked at my source code. And for grins, I went to the Facebook debugger to see what image(s) it pulls up for the og:image meta tag. The image I have designated does not appear.January 12, 2015 at 8:48 am #137174Kary
MemberIs there a function I can write that uses the front-page.php? I am not good at writing functions code. But instead of
if ( is_front_page() )
would a genesis hook specific to the front-page.php work?parallax_home_genesis_meta
January 12, 2015 at 9:58 am #137177Carlo
MemberHi Kary. The reason you got a Dreamweaver error is because your code did not declare the function. Try this:
function medic_home_og() { if ( is_front_page() ) echo '<meta property="og:image" content="http://link/to/your/og/image/file" />'; } add_action( 'wp_head', 'medic_home_og', 5);
I also changed
is_home()
tois_front_page()
becauseis_home()
is for the latest posts index regardless of whether it's the front page.is_front_page()
is for the front page regardless of whether it's a static page or your latest posts.
January 12, 2015 at 10:36 am #137190Kary
MemberUnfortunately, it still is not working for me. This is the code I've uploaded via my functions file
function medic_home_og() { if ( is_front_page() ) echo '<meta property="og:image" content="http://techiemuse.com/wp-content/uploads/2015/01/TechieMuse.png" />'; } add_action( 'wp_head', 'medic_home_og', 5);
When I check this site, the image does not appear. I have clicked the "rescrape" button. https://developers.facebook.com/tools/debug/
Someone else suggested to try
if ( is_home() || is_front_page() )
as the conditional statement. But this isn't working for me either.January 12, 2015 at 11:14 am #137198Kary
MemberOkay...got it to work finally. Thanks for your help. This is the code that I used and I am finally able to see the image in the Facebook debugger.
function change_home_og() { if ( is_home() || is_front_page() ) echo '<meta property="og:image" content="http://techiemuse.com/wp-content/uploads/2015/01/TechieMuse.png" />'; } add_action( 'wp_head', 'change_home_og', 5);
For anyone who wants to do this, make absolutely certain your image is 200x200 or Facebook will pull something else from the page that is that size. Not sure if it can be a large (square) image. But the 200x200 definitely worked for me.
January 14, 2015 at 3:37 am #137400Carlo
MemberI'm glad you got it to work Kary. I still think that
if ( is_front_page() )
is better thanif ( is_home() || is_front_page() )
because there's a chance that usingif ( is_home() || is_front_page() )
will cause your facebook image to show on another page other than the front page, depending on how your site is configured. But that's up to you.
-
AuthorPosts
- The topic ‘"Featured Image" for Homepage when Shared’ is closed to new replies.