Created
July 8, 2015 11:00
-
-
Save ckchaudhary/4a930f90a92d21349957 to your computer and use it in GitHub Desktop.
og description for buddypress groups and activities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_head', 'dtk_buddypress_og_data', 11 ); | |
function dtk_buddypress_og_data(){ | |
if( bp_is_single_activity() ){ | |
if ( bp_has_activities( 'display_comments=threaded&show_hidden=true&include=' . bp_current_action() ) ){ | |
while ( bp_activities() ){ | |
bp_the_activity(); | |
$title = wp_strip_all_tags( bp_get_activity_action() ); | |
$content = wp_strip_all_tags( bp_get_activity_content_body() ); | |
$url = bp_activity_get_permalink( bp_get_activity_id() ); | |
$content = substr( $content, 0, 300 ); | |
?> | |
<meta property="og:type" content="article" /> | |
<meta property="og:title" content="<?php echo esc_attr( $title );?>" /> | |
<meta property="og:url" content="<?php echo $url;?>" /> | |
<meta property="og:description" content="<?php echo esc_attr( $content );?>" /> | |
<?php | |
} | |
} | |
} | |
if( bp_is_group() ){ | |
if ( bp_has_groups() ){ | |
while ( bp_groups() ){ | |
bp_the_group(); | |
$title = wp_strip_all_tags( bp_get_group_name() ); | |
$content = wp_strip_all_tags( bp_get_group_description() ); | |
$url = bp_get_group_permalink(); | |
$content = substr( $content, 0, 300 ); | |
?> | |
<meta property="og:type" content="article" /> | |
<meta property="og:title" content="<?php echo esc_attr( $title );?>" /> | |
<meta property="og:url" content="<?php echo $url;?>" /> | |
<meta property="og:description" content="<?php echo esc_attr( $content );?>" /> | |
<?php | |
global $dit; | |
$img_url = $dit['groups_types']->gtype_group_image_url(bp_get_group_id()); | |
if( $img_url ){ | |
?> | |
<meta property="og:image" content="<?php echo esc_attr( $img_url );?>" /> | |
<?php | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment