/** * Add Open Graph protocol markup to <head> * * @since 1.0 */ function fb_add_og_protocol() { global $post; $meta_tags = array('http://ogp.me/ns#locale' => fb_get_locale(), 'http://ogp.me/ns#site_name' => get_bloginfo('name'), 'http://ogp.me/ns#type' => 'website'); if (is_home() || is_front_page()) { $meta_tags['http://ogp.me/ns#title'] = get_bloginfo('name'); $meta_tags['http://ogp.me/ns#description'] = get_bloginfo('description'); } else { if (is_single()) { $post_type = get_post_type(); $meta_tags['http://ogp.me/ns#type'] = 'article'; $meta_tags['http://ogp.me/ns#url'] = apply_filters('rel_canonical', get_permalink()); if (post_type_supports($post_type, 'title')) { $meta_tags['http://ogp.me/ns#title'] = get_the_title(); } if (post_type_supports($post_type, 'excerpt')) { // thanks to Angelo Mandato (http://wordpress.org/support/topic/plugin-facebook-plugin-conflicts-with-powerpress?replies=16) // Strip and format the wordpress way, but don't apply any other filters which adds junk that ends up getitng stripped back out if (!post_password_required($post)) { // First lets get the post excerpt (shouldn't have any html, but anyone can enter anything...) $meta_tags['http://ogp.me/ns#description'] = fb_strip_and_format_desc($post); } } $meta_tags['http://ogp.me/ns/article#published_time'] = get_the_date('c'); $meta_tags['http://ogp.me/ns/article#modified_time'] = get_the_modified_date('c'); if (post_type_supports($post_type, 'author') && isset($post->post_author)) { $meta_tags['http://ogp.me/ns/article#author'] = get_author_posts_url($post->post_author); } // add the first category as a section. all other categories as tags $cat_ids = get_the_category(); if (!empty($cat_ids)) { $cat = get_category($cat_ids[0]); if (!empty($cat)) { $meta_tags['http://ogp.me/ns/article#section'] = $cat->name; } //output the rest of the categories as tags unset($cat_ids[0]); if (!empty($cat_ids)) { $meta_tags['http://ogp.me/ns/article#tag'] = array(); foreach ($cat_ids as $cat_id) { $cat = get_category($cat_id); $meta_tags['http://ogp.me/ns/article#tag'][] = $cat->name; unset($cat); } } } // add tags. treat tags as lower priority than multiple categories $tags = get_the_tags(); if ($tags) { if (!array_key_exists('http://ogp.me/ns/article#tag', $meta_tags)) { $meta_tags['http://ogp.me/ns/article#tag'] = array(); } foreach ($tags as $tag) { $meta_tags['http://ogp.me/ns/article#tag'][] = $tag->name; } } // does current post type and the current theme support post thumbnails? if (post_type_supports($post_type, 'thumbnail') && function_exists('has_post_thumbnail') && has_post_thumbnail()) { list($post_thumbnail_url, $post_thumbnail_width, $post_thumbnail_height) = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); if (!empty($post_thumbnail_url)) { $image = array('url' => $post_thumbnail_url); if (!empty($post_thumbnail_width)) { $image['width'] = absint($post_thumbnail_width); } if (!empty($post_thumbnail_height)) { $image['height'] = absint($post_thumbnail_height); } $meta_tags['http://ogp.me/ns#image'] = array($image); } } } else { if (is_author() && isset($post->post_author)) { $meta_tags['http://ogp.me/ns#type'] = 'profile'; $meta_tags['http://ogp.me/ns/profile#first_name'] = get_the_author_meta('first_name', $post->post_author); $meta_tags['http://ogp.me/ns/profile#last_name'] = get_the_author_meta('last_name', $post->post_author); if (is_multi_author()) { $meta_tags['http://ogp.me/ns/profile#username'] = get_the_author_meta('login', $post->post_author); } } else { if (is_page()) { $meta_tags['http://ogp.me/ns#type'] = 'article'; $meta_tags['http://ogp.me/ns#title'] = get_the_title(); $meta_tags['http://ogp.me/ns#url'] = apply_filters('rel_canonical', get_permalink()); } } } } $options = get_option('fb_options'); if (!empty($options['app_id'])) { $meta_tags['http://ogp.me/ns/fb#app_id'] = $options['app_id']; } $meta_tags = apply_filters('fb_meta_tags', $meta_tags, $post); foreach ($meta_tags as $property => $content) { fb_output_og_protocol($property, $content); } }
/** * Inits the Facebook JavaScript SDK. * * @since 1.0 */ function fb_js_sdk_setup() { $options = get_option('fb_options'); if (empty($options['app_id'])) { return; } $args = apply_filters('fb_init', array('appId' => $options['app_id'], 'channelUrl' => add_query_arg('fb-channel-file', 1, site_url('/')), 'status' => true, 'cookie' => true, 'xfbml' => true, 'oauth' => true)); echo '<script type="text/javascript">window.fbAsyncInit=function(){FB.init(' . json_encode($args) . ');'; do_action('fb_async_init', $args); echo '}</script>'; $locale = fb_get_locale(); if (!$locale) { return; } wp_enqueue_script('fb-connect', (is_ssl() ? 'https' : 'http') . '://connect.facebook.net/' . $locale . '/all.js', array(), null, true); add_action('wp_footer', 'fb_root'); }