Home › Forums › Calendar Products › Events Calendar PRO › Add Facebook Compatible Meta Data Tags to Each Event Page
- This topic has 12 replies, 3 voices, and was last updated 10 years, 9 months ago by
Support Droid.
-
AuthorPosts
-
February 26, 2014 at 8:41 am #109644
sciotomile
ParticipantHas anyone figured out a way to add meta tags to individual events so that when a user clicks on an inserted “share on facebook” button, the event description and featured image is shown rather than random images and the latest blog post description?
http://www.sciotomile.com/event-listing/columbus-arts-festival/
February 26, 2014 at 10:41 am #109695sciotomile
ParticipantOkay… I’ve added this code to my theme functions:
http://pastebin.com/Gnipe9jPI’ve also installed WordPress SEO by Yoast. That seems to have fixed things, I think… Does the above code make sense? Will it work?
February 26, 2014 at 10:53 am #109715sciotomile
ParticipantYeah… it still wants to pull the “default thumbnail” I create first and not the actual posts thumbnail. It shows both options if you use the arrow before you click post on the facebook share window, but that isn’t exactly what I want… I am confused why it is showing up since I placed the code that assigns a default op image in a if/else loop.
February 26, 2014 at 11:12 am #109722snorton
ParticipantIt looks like you’re echoing nothing if there is a post thumbnail and a placeholder image if the featured image has not been set?
Add this to your functions.php file to get it to (hopefully) work properly:
<?php
add_action(‘wp_head’, ‘my_featured_fb_image’);function my_featured_fb_image($post_id = null, $size = ‘full’) {
$post_id = get_the_ID();
$image_src = get_post_thumbnail( $post_id , $size );
$fb_meta_tag = ”;
if ( !empty( $image_src ) ) {
$fb_meta_tag .= ‘<meta property=”og:image” content=”‘ . $image_src . ‘” >’;
echo $fb_meta_tag;
}
else {
echo ‘<meta property=”og:image” content=”http://www.sciotomile.com/wp-content/uploads/2014/02/Default_Feature_Thumbnail.png”/>’;
}
}
?>Also, for what it’s worth, here’s a ref to FB’s doc on the subject of Open Graph:
https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content#tagsFebruary 26, 2014 at 11:34 am #109725sciotomile
ParticipantSnorton — Something in your code caused my entire site to crash and fail to load. I removed it from the functions file and the site returned. Perhaps some extra formatting is coming from putting code directly into a post on the forum. Can you post to pastebin.com or something? Thanks!
I am wondering if $fb_meta_tag = ”; is actually supposed to be $fb_meta_tag = ”;
February 26, 2014 at 11:36 am #109727sciotomile
ParticipantWell my replied post comfirmed it… when you post on this forum two individual quotation marks (‘ and ‘) are combined into “… Anyway, if you can post using pastebin I would really appreciate it.
February 26, 2014 at 12:03 pm #109737sciotomile
ParticipantI tried correcting the auto formating of the quotation marks in the above code, but it still causes the site to fail…
February 26, 2014 at 12:03 pm #109739snorton
ParticipantWell, whoops! I knew better but did it anyway.
http://pastebin.com/XQGerpgVFebruary 26, 2014 at 12:04 pm #109740snorton
ParticipantThis also checks if you’re on a tribe event page.
February 26, 2014 at 12:09 pm #109741sciotomile
ParticipantWell it doesn’t cause the entire site to crash, but the event page will not load if I put this code in functions.
February 26, 2014 at 12:16 pm #109751snorton
ParticipantLet me try this again. Tested on localhost and it returns what we’re looking for – my apologies for the messed up function above!!
February 26, 2014 at 12:25 pm #109760sciotomile
ParticipantThat worked! Thanks!
July 7, 2015 at 6:30 am #983094Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
AuthorPosts
- The topic ‘Add Facebook Compatible Meta Data Tags to Each Event Page’ is closed to new replies.
