Setting up yoast filters for open graph and twitter.
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 15 Nov 2016 19:02:49 +0000 (14:02 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 15 Nov 2016 19:02:49 +0000 (14:02 -0500)
Set the title and description for open graph and twitter within the
yoast filters.

setup/frontHooks.php

index 0a25e54..c6a11b5 100644 (file)
@@ -146,12 +146,33 @@ if (strpos(GLM_MEMBERS_PLUGIN_CURRENT_URL, $this->config['settings']['canonical_
 
     // Get the member name for use in the page title
     global $wpdb;
-    $GLOBALS['glmMembName'] = $wpdb->get_var( "SELECT name FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "members WHERE member_slug = '".$GLOBALS['glmDetailSlug']."'" );
+    $memberData = $wpdb->get_row(
+        "SELECT T.name,I.short_descr
+           FROM ".GLM_MEMBERS_PLUGIN_DB_PREFIX . "members T,
+                ".GLM_MEMBERS_PLUGIN_DB_PREFIX."member_info I
+          WHERE T.member_slug = '".$GLOBALS['glmDetailSlug']."'
+            AND T.id = I.member",
+        ARRAY_A
+    );
+    $GLOBALS['glmMembName']  = $memberData['name'];
+    $GLOBALS['glmMembIntro'] = $memberData['short_descr'];
 
     // Set the page title to the member name - Using low priority so it's the last to set the title!
     add_filter('wp_title', function($title) {
         return $GLOBALS['glmMembName'];
     }, 99, 1);
+    add_filter( 'wpseo_opengraph_title', function($tag){
+        return $GLOBALS['glmMembName'];
+    }, 99, 1 );
+    add_filter( 'wpseo_opengraph_desc', function($tag){
+        return $GLOBALS['glmMembIntro'];
+    }, 99, 1 );
+    add_filter( 'wpseo_twitter_title', function($tag){
+        return $GLOBALS['glmMembName'];
+    }, 99, 1 );
+    add_filter( 'wpseo_twitter_description', function($tag){
+        return $GLOBALS['glmMembIntro'];
+    }, 99, 1 );
 }
 
 // Squash Bread Crumbs if using Breadcrumb NavXT plugin -- NEED TO CREATE A MANAGEMENT OPTION FOR THIS TO TURN IT ON/OFF