Facebook OpenGraph Meta Tags
Permalink Browser Info Environment
How do access a post title from within the wordpress_entires block controller? I would like to add Facebook OpenGraph meta tags.
public function on_page_view() { // this puts your string to output in // the Loader::element('header_required') // class $this->addHeaderItem("<meta property=\"og:url\" content=\"".$this->getCurrentPageURL()."\"/>\n"); $this->addHeaderItem("<meta property=\"og:title\" content=\"\"/>\n"); }
Type: | Discussion |
---|---|
Status: | New |
Ah, there's going to be a problem with this approach.
This won't work with AJAX, because adding a header item needs to happen while the page is generated. An AJAX request will run (and find the post title) after the page has been loaded.
However, I have a script that checks the user agent for search engines, and switches to cURL automatically.
If we can make sure that we have the user agent for Facebook, I can make sure we trigger the cURL switch, and then I can add these tags (do we only need these two?) into the add-on by default.
This won't work with AJAX, because adding a header item needs to happen while the page is generated. An AJAX request will run (and find the post title) after the page has been loaded.
However, I have a script that checks the user agent for search engines, and switches to cURL automatically.
If we can make sure that we have the user agent for Facebook, I can make sure we trigger the cURL switch, and then I can add these tags (do we only need these two?) into the add-on by default.
The user agent for Facebook is currently "facebookexternalhit/1.1 (+https://www.facebook.com/externalhit_uatext.php)".
Take a look at the Open Graph Protocol reference (https://developers.facebook.com/docs/opengraphprotocol/). There are a number of applicable meta tags that are relevant.
For my purposes, the following are desired (there are a number of others that are applicable to Wordpress):
- og:title
- og:url (pretty url)
- og:image
- og:site_name
- og:description
My understanding is that LinkedIn also used the Open Graph Protocol. The user agent for LinkedIn is "LinkedInBot/1.0 (compatible; Mozilla/5.0; Jakarta Commons-HttpClient/3.1 +http://www.linkedin.com)".
Take a look at the Open Graph Protocol reference (https://developers.facebook.com/docs/opengraphprotocol/). There are a number of applicable meta tags that are relevant.
For my purposes, the following are desired (there are a number of others that are applicable to Wordpress):
- og:title
- og:url (pretty url)
- og:image
- og:site_name
- og:description
My understanding is that LinkedIn also used the Open Graph Protocol. The user agent for LinkedIn is "LinkedInBot/1.0 (compatible; Mozilla/5.0; Jakarta Commons-HttpClient/3.1 +http://www.linkedin.com)".
Thank you! I'll see if I can add these in by default :)
Thanks for the update. Do you have any idea when this may be complete? I ask because my manager pings me weekly about this, and I would like to install a single update to address this simultaneously with my other support requests that have been resolved (because I have made several customizations to the package).
Looking forward to this new feature... :)
Can we add this into the add-on by default? Is there anything more we would need to better support Facebook integration?