Added code to frontHooks.php for canonical page fix.
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 7 Jul 2016 15:34:19 +0000 (11:34 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 7 Jul 2016 15:34:19 +0000 (11:34 -0400)
setup/frontHooks.php

index 02265ed..3ef47f7 100644 (file)
@@ -45,6 +45,35 @@ if ( ! isset( $rules['('.$this->config['settings']['canonical_package_page'].')/
 
 }
 
+/*
+ * Package Detail Page Canonical URL Fix
+ *
+ * Since the package detail pages are actually all the same page, and since WordPress has a specific
+ * canonical URL for that page, we need to override the rel='canonical' value in the page header.
+ *
+ * The code below checks if we're on a package detail page and if so returns the package slug so that
+ * can be added to the URL. The matching apply_filters is in the main plugin in setup/frontHooks.php.
+ */
+add_filter('glm_rel_canonical_slug', function($detailSlug) {
+
+    // If another add-on already supplied the detail slug, then just return that.
+    if ($detailSlug != false) {
+        return $detailSlug;
+    }
+
+    // Check if the page is a package-detail page use the correct
+    if (strpos(GLM_MEMBERS_PLUGIN_CURRENT_URL, $this->config['settings']['canonical_package_page']) > 0) {
+
+            // Parse out only the package slug and use that
+            $m = array();
+            preg_match('|.*/'.$this->config['settings']['canonical_package_page'].'/([^/]*).*|', GLM_MEMBERS_PLUGIN_CURRENT_URL, $m );
+            $detailSlug = $m[1];
+
+    }
+
+    return $detailSlug;
+});
+
 // Add package slug query var
 add_filter('query_vars', function($vars) {
     array_push($vars, 'packageslug');