Add Facebook Compatible Meta Data Tags to Each Event Page

Home Forums Calendar Products Events Calendar PRO Add Facebook Compatible Meta Data Tags to Each Event Page

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #109644
    sciotomile
    Participant

    Has 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/

    #109695
    sciotomile
    Participant

    Okay… I’ve added this code to my theme functions:
    http://pastebin.com/Gnipe9jP

    I’ve also installed WordPress SEO by Yoast. That seems to have fixed things, I think… Does the above code make sense? Will it work?

    #109715
    sciotomile
    Participant

    Yeah… 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.

    #109722
    snorton
    Participant

    It 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”/>&#8217;;
    }
    }
    ?>

    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#tags

    #109725
    sciotomile
    Participant

    Snorton — 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 = ”;

    #109727
    sciotomile
    Participant

    Well 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.

    #109737
    sciotomile
    Participant

    I tried correcting the auto formating of the quotation marks in the above code, but it still causes the site to fail…

    #109739
    snorton
    Participant

    Well, whoops! I knew better but did it anyway.
    http://pastebin.com/XQGerpgV

    #109740
    snorton
    Participant

    This also checks if you’re on a tribe event page.

    #109741
    sciotomile
    Participant

    Well it doesn’t cause the entire site to crash, but the event page will not load if I put this code in functions.

    #109751
    snorton
    Participant

    Let me try this again. Tested on localhost and it returns what we’re looking for – my apologies for the messed up function above!!

    http://pastebin.com/Gs0DYgyH

    #109760
    sciotomile
    Participant

    That worked! Thanks!

    #983094
    Support Droid
    Keymaster

    This 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.

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘Add Facebook Compatible Meta Data Tags to Each Event Page’ is closed to new replies.