Last active
October 24, 2016 14:16
-
-
Save sareiodata/dc89f3f92d0731701575d3507b456dd5 to your computer and use it in GitHub Desktop.
filters for improving user listing SEO stuff
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
/* | |
* Make user listing work with the nicename. Tags: user listing, nicename | |
*/ | |
add_filter('wppb_userlisting_get_user_by_id', create_function('', 'return false;')); | |
// Filter wp_title for single user listing | |
function single_user_list_filter_wp_title( $title, $sep ) { | |
$userID = wppb_get_query_var('username'); | |
if ( empty( $userID ) ) | |
return $title; | |
$user_object = new WP_User( $userID ); | |
$title .= ' - '; | |
$title .= $user_object->first_name; | |
$title .= ' '; | |
$title .= $user_object->last_name; | |
return $title; | |
} | |
add_filter( 'wp_title', 'single_user_list_filter_wp_title', 99, 2 ); | |
// Filter canonical url so profiles are indexed by google | |
function single_user_list_canonical_url( $canonical_url, $post ) { | |
$userID = wppb_get_query_var('username'); | |
if ( empty( $userID ) ) | |
return $canonical_url; | |
$canonical_url .= 'user/' . $userID; | |
return $canonical_url; | |
} | |
add_filter( 'get_canonical_url', 'single_user_list_canonical_url', 99, 2 ); | |
// Filter canonical url so profiles are indexed by google | |
function single_user_description_meta( ) { | |
$userID = wppb_get_query_var('username'); | |
if ( empty( $userID ) ) | |
return; | |
$user_object = new WP_User( $userID ); | |
echo '<meta property="og:description" content="'. $user_object->description .'" />'; | |
} | |
add_action( 'wp_head', 'single_user_description_meta'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment