diff --git a/includes/core/class-permalinks.php b/includes/core/class-permalinks.php
index c7cd6048..642eaa9a 100644
--- a/includes/core/class-permalinks.php
+++ b/includes/core/class-permalinks.php
@@ -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;
diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php
index 429a13fb..7f7372db 100644
--- a/includes/core/um-actions-profile.php
+++ b/includes/core/um-actions-profile.php
@@ -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
@@ -673,9 +677,8 @@ function um_profile_dynamic_meta_desc() {
?>
-
-
+
diff --git a/includes/core/um-filters-profile.php b/includes/core/um-filters-profile.php
index c7277f78..97cc7cb5 100644
--- a/includes/core/um-filters-profile.php
+++ b/includes/core/um-filters-profile.php
@@ -77,6 +77,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
+ *
+ * @example
+ *
+ */
+ $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
*