Created
November 14, 2024 09:45
-
-
Save dwanjuki/2ed28e91daf5a76d8ac2a8cf3a74370a to your computer and use it in GitHub Desktop.
Set a custom page title for PMPro Member Directory Profile pages
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 | |
/** | |
* Set a custom page title for PMPro Member Directory Profile pages | |
* | |
* 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/ | |
*/ | |
function my_pmpromd_filter_document_title( $title ) { | |
global $pmpro_pages; | |
// Bail if we're not on the profile page. | |
if ( empty( $pmpro_pages['profile'] ) || ! is_page( $pmpro_pages['profile'] ) ) { | |
return; | |
} | |
$site_title = get_bloginfo( 'name' ); | |
$pu = pmpromd_get_user(); | |
$display_name = pmpro_member_directory_get_member_display_name( $pu ); | |
$title = $display_name . ' - ' . $site_title; | |
return $title; | |
} | |
add_filter( 'pre_get_document_title', 'my_pmpromd_filter_document_title' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment