@modemlooper
cc @chouf1
cc @henrywright-1
I have figured out how to get this in the header, without hacking bp or running a custom sql query.
So basically, what I did was create a function that loads the data by using global $bp, and a very powerful $bp function known as bp_activity_get
Now that I’ve dissected your bp-activity-functions.php file the sky is the limit.
Here’s a very small sample of this in action (mine also grabs rtmedia etc, now finally facebook will grab any images uploaded and all the content, finally)
First, you want a function that is going to run in the <head> tag like so:
add_action( 'wp_head', 'insert_fb_in_head', 5 );
So it’s going to run in wp_head (yay) and it will be called ‘insert_fb_in_head’, priority lvl 5.
You may also want to load bp_head()
before you run wp_head()
in your header.php
file. I didn’t test it the other way around, just know this WORKS:
So here comes the magic:
function insert_fb_in_head() {
global $post;
global $bp;
if (bp_is_current_component('activity') ) {
$title = "HVAC Hacks";
$description = "Here's Why You Choose a Professional";
$keywords = "hvac, hvac hacks, hvac hacks and other screw ups, hvac memes, hvac meme";
$domain = "HVAC-Hacks.com";
$image = $default_image;
$activity_id = $bp->current_action;
if ($activity_id) {
$get_act = bp_activity_get(array('in'=>$activity_id));
$activities = ($get_act['activities']);
foreach ($activities as $activity) {
$description = strip_tags($activity->action);
$image = html_get_attr($activity->content, "img","src");
}
//HTML META
echo '<meta name="description" content="'.$description.'">';
echo '<meta name="keywords" content="'.$keywords.'">';
//FACEBOOK
echo '<meta property="og:title" content="' . $title . '"/>';
echo '<meta property="og:type" content="article"/>';
echo '<meta property="og:url" content="http://www.hvac-hacks.com'.$_SERVER['REQUEST_URI'].'"/>';
echo '<meta property="og:site_name" content="'.$title.'"/>';
echo '<meta property="og:description" content="'.$description.'"/>';
echo '<meta property="og:image" content="' . $image . '"/>';
//TWITTER
echo ' <meta name="twitter:card" content="photo">
<meta name="twitter:site" content="@hvachacks">
<meta name="twitter:creator" content="@hvachacks">
<meta name="twitter:title" content="'.$title.'">
<meta name="twitter:domain" content="www.hvac-hacks.com">
<meta name="twitter:image:src" content="'.$image.'">';
return;
}
}
Oh and here’s the proof: https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.hvac-hacks.com%2Fmembers%2Fgene-warren-391%2Factivity%2F4293%2F
That’s facebook’s debugger tool telling me it grabbed all the necessary info…. yay… win..