Last active
May 12, 2025 07:47
-
-
Save JarrydLong/4c4d26efa97ed656e5023e22da9f668f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 //do not copy | |
/** | |
* This recipe unhooks the existing document title parts hook and | |
* uses the member's first and last names in the title. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
// Unhook the existing function. | |
remove_filter( 'document_title_parts', 'pmpromd_document_title_parts' ); | |
// Define a new function that uses first_name and last_name. | |
function mypmpro_custom_document_title_parts_with_names( $title_parts ) { | |
global $main_post_id, $post, $pmpro_pages; | |
if( empty( $pmpro_pages['profile'] ) ) { | |
return $title_parts; | |
} | |
if( ! is_page( $pmpro_pages['profile'] ) ){ | |
return $title_parts; | |
} | |
if ( isset( $post->ID ) && $post->ID == $main_post_id ) { | |
$pu = pmpromd_get_user(); | |
if ( ! empty( $pu->first_name ) || ! empty( $pu->last_name ) ) { | |
$first_name = isset( $pu->first_name ) ? $pu->first_name : ''; | |
$last_name = isset( $pu->last_name ) ? $pu->last_name : ''; | |
if( empty( $first_name ) && empty( $last_name ) ) { | |
$display_name = pmpro_member_directory_get_member_display_name( $pu ); | |
if ( ! empty( $display_name ) ) { | |
$title_parts['title'] = $display_name; // Set the main title part. | |
} | |
} else { | |
$title_parts['title'] = trim( $first_name . ' ' . $last_name ); | |
} | |
} | |
} | |
return $title_parts; | |
} | |
add_filter( 'document_title_parts', 'mypmpro_custom_document_title_parts_with_names', 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment