mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
Fixed: SEO link canonical for the profile page
This commit is contained in:
@@ -39,9 +39,9 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
|
||||
//add_action( 'um_user_after_updating_profile', array( &$this, 'profile_url' ), 1 );
|
||||
|
||||
remove_action( 'wp_head', 'rel_canonical' );
|
||||
|
||||
add_action( 'wp_head', array( &$this, 'um_rel_canonical_' ), 9 );
|
||||
/* @deprecated since version 2.1.7 */
|
||||
//remove_action( 'wp_head', 'rel_canonical' );
|
||||
//add_action( 'wp_head', array( &$this, 'um_rel_canonical_' ), 9 );
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
|
||||
|
||||
/**
|
||||
* SEO canonical href bugfix
|
||||
* @deprecated since version 2.1.7
|
||||
* @see function um_profile_remove_wpseo()
|
||||
*/
|
||||
function um_rel_canonical_() {
|
||||
global $wp_the_query;
|
||||
|
||||
@@ -608,9 +608,13 @@ if ( !function_exists( 'um_profile_remove_wpseo' ) ) {
|
||||
/* Yoast SEO 14.1 */
|
||||
remove_all_filters( 'wpseo_head' );
|
||||
|
||||
/* Restore title and canonical if broken */
|
||||
if( ! has_action( 'wp_head', '_wp_render_title_tag' ) ){
|
||||
add_action( 'wp_head', '_wp_render_title_tag', 18 );
|
||||
}
|
||||
if( ! has_action( 'wp_head', 'rel_canonical' ) ){
|
||||
add_action( 'wp_head', 'rel_canonical', 18 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -619,7 +623,7 @@ add_action( 'get_header', 'um_profile_remove_wpseo', 8 );
|
||||
|
||||
|
||||
/**
|
||||
* Meta description
|
||||
* The profile page SEO tags
|
||||
*
|
||||
* @see https://ogp.me/ - The Open Graph protocol
|
||||
* @see https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary - The Twitter Summary card
|
||||
@@ -659,9 +663,8 @@ function um_profile_dynamic_meta_desc() {
|
||||
?>
|
||||
<!-- START - Ultimate Member profile SEO meta tags -->
|
||||
|
||||
<link rel="canonical" href="<?php echo esc_url( $url ); ?>"/>
|
||||
<link rel="image_src" href="<?php echo esc_url( $image ); ?>"/>
|
||||
|
||||
|
||||
<meta name="description" content="<?php echo esc_attr( $description ); ?>"/>
|
||||
|
||||
<meta property="og:type" content="profile"/>
|
||||
|
||||
@@ -65,6 +65,55 @@ function um_dynamic_user_profile_title( $title, $id = '' ) {
|
||||
add_filter( 'the_title', 'um_dynamic_user_profile_title', 100000, 2 );
|
||||
|
||||
|
||||
/**
|
||||
* Fix SEO canonical for the profile page
|
||||
*
|
||||
* @param string $canonical_url The canonical URL.
|
||||
* @param WP_Post $post Optional. Post ID or object. Default is global `$post`.
|
||||
* @return string|false The canonical URL, or false if current URL is canonical.
|
||||
*/
|
||||
function um_get_canonical_url( $canonical_url, $post ){
|
||||
|
||||
if( UM()->config()->permalinks['user'] == $post->ID ) {
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_allow_canonical__filter
|
||||
* @description Allow canonical
|
||||
* @input_vars
|
||||
* [{"var":"$allow_canonical","type":"bool","desc":"Allow?"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_allow_canonical__filter', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_allow_canonical__filter', 'my_allow_canonical', 10, 1 );
|
||||
* function my_allow_canonical( $allow_canonical ) {
|
||||
* // your code here
|
||||
* return $allow_canonical;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$enable_canonical = apply_filters( "um_allow_canonical__filter", true );
|
||||
|
||||
if( $enable_canonical ){
|
||||
$url = um_user_profile_url( um_get_requested_user() );
|
||||
$canonical_url = $url === home_url( $_SERVER['REQUEST_URI'] ) ? false : $url;
|
||||
|
||||
if ( $page = get_query_var('cpage') ){
|
||||
$canonical_url = get_comments_pagenum_link( $page );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $canonical_url;
|
||||
}
|
||||
add_filter( 'get_canonical_url', 'um_get_canonical_url', 20, 2 );
|
||||
|
||||
|
||||
/**
|
||||
* Add cover photo label of file size limit
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user