Add open graph metadata using JDocument::setMetaData()
$document->setMetaData('og:image', 'https://cdn.joomla.org/images/Joomla_logo.png');
When rendering, the resulting meta tag per http://ogp.me/ should be:
<meta property="og:image" content="https://cdn.joomla.org/images/Joomla_logo.png" />
When rendering, the resulting meta tag is:
<meta name="og:image" content="https://cdn.joomla.org/images/Joomla_logo.png" />
The use of JDocument::addCustomTag()
is required to mitigate this due to the lack of native support.
Category | ⇒ | Libraries |
Labels |
Added:
?
|
you also need to add the open graph namespace in the html tag right?
I honestly don't know but if so that presents another issue in that there
is absolutely no way without an onAfterRender plugin to set stuff on the
base HTML tag.
On Sunday, May 29, 2016, andrepereiradasilva notifications@github.com
wrote:
you also need to add the open graph namespace in the hmtl tag right?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#10671 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAWfoXsdxk39_GiKh5vuApXDcZAVRk6Iks5qGfjwgaJpZM4IpVSU
.
we would need some sort of an jdoc include in the template for that
Something like:
<html lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>"<jdoc:include type="namespaces" />>
And them make JDocument render those with something like
$doc->addHtmlNameSpace($attribute, $value);
$doc->addHtmlNameSpace("prefix", "og: http://ogp.me/ns#");
$doc->addHtmlNameSpace("prefix", "fb: http://ogp.me/ns/fb#");
So it can render
<!DOCTYPE html>
<html lang="en-gb" dir="ltr" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
Since html is extensible trough prefixes/namespaces it would be godd if joomla could deal with this.
In my extension it seems to work without the namespace and the Facebook debug tool also doesn't complain about the missing namespace.
yes it works, but it's not valid HTML code if you don't add the namespace right?
See http://ogp.me
The namespace isn't needed for it to be valid HTML. OpenGraph uses regular HTML elements (namely the <meta>
tag). It's only the values which define the OpenGraph functionality.
you're right, just test it in the validator (https://validator.w3.org/#validate_by_input) and says it's valid HTML without the prefix.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
</head>
<body>
<p>test</p>
</body>
</html>
IIRC sometime ago the validator add issues with that.
But since now it says it's valid i think you're right.
So it seems for this case you don't need the namespace afterall.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-05-31 20:38:50 |
Closed_By | ⇒ | brianteeman |
Closed as we have a a PR #10682
We could add a new parameter to the
JDocument::setMetaData()
that can be set totrue
for open graph. (See this file and line https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/document/document.php#l424).And for the head renderer a check to generate the correct html (see this file and line https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/document/renderer/html/head.php#L92)