Making WordPress.org

Ticket #4277: 4277.diff

File 4277.diff, 1.4 KB (added by tellyworth, 4 years ago)
  • functions.php

     
    5858add_action( 'wp_head', 'profiles_output_rel_canonical' );
    5959
    6060/**
     61 * Outputs opengraph tags for user profiles.
     62 */
     63function profiles_output_opengraph() {
     64        if ( !bp_is_user_profile() || !bp_is_current_action( 'public' ) ) {
     65                return;
     66        }
     67        $bio       = bp_get_profile_field_data( array( 'field' => 'About Me' ) );
     68        $url       = bp_displayed_user_domain();
     69        $image_url = get_avatar_url( bp_displayed_user_id(), array( 'size' => 1024 ) );
     70        $full_name = bp_get_displayed_user_fullname();
     71        $username  = bp_get_displayed_user_username();
     72
     73?>
     74<meta property="og:type" content="profile" />
     75<meta property="og:title" content="<?php echo esc_attr( $full_name ); ?> - WordPress user profile" />
     76<meta property="og:description" content="<?php echo esc_attr( wp_trim_words( $bio, 25, '&#8230;' ) ); ?>" />
     77<meta property="og:url" content="<?php echo esc_attr( $url ); ?>" />
     78<meta property="og:site_name" content="WordPress" />
     79<meta property="og:image" content="<?php echo esc_attr( $image_url ); ?>" />
     80<meta property="profile:username" content="<?php echo esc_attr( $username ); ?>" />
     81<?
     82}
     83add_action( 'wp_head', 'profiles_output_opengraph' );
     84
     85/**
    6186 * Hide the WordPress admin bar
    6287 */
    6388function profiles_hide_admin_bar() {