动态 Facebook Open Graph 标签可能吗? [英] Dynamic Facebook Open Graph tags possible?

查看:32
本文介绍了动态 Facebook Open Graph 标签可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态更改我的 <meta property="og:image" content="#"><meta property="og:title" content="#"> 标签使用 jQuery(如下).当我在 Chrome 中通过inspect"查看代码时,标签已成功更改.

I'm dynamically changing my <meta property="og:image" content="#"> and <meta property="og:title" content="#"> tags using jQuery (below). When I view the code via 'inspect' in Chrome, the tags have successfully been changed.

HTML:

<meta property="og:title" content="#">
<meta property="og:image" content="#">

jQuery:

$("meta[property='og:title']").attr("content", data.name);
$("meta[property='og:image']").attr("content", data.thumbnail.url);

但是 Facebook 调试器工具 仍然显示 content="#" 每个.我假设这是因为 Facebook 在 Javascript 有机会替换内容之前读取了源代码.

But the Facebook debugger tool is still showing content="#" for each. I'm assuming this is because Facebook reads the source code, before Javascript has a chance to replace the content.

有没有办法解决这个问题?

Is there a way around this?

谢谢.

推荐答案

Facebook 根本不解析 JavaScript,您不能使用动态 Open Graph 标签.无论如何,即时更改它们确实没有意义.

Facebook does not parse JavaScript at all, you can´t use dynamic Open Graph tags. It does not really make sense to change them on the fly anyway.

您只能在服务器上动态更改 OG 标签 - 显然.例如:https://yourdomain.com/dynamicogtags.php?title=xxx&description=xxx

You can only change the OG tags dynamically on the server - obviously. For example: https://yourdomain.com/dynamicogtags.php?title=xxx&description=xxx

<meta property="og:title" content="<?php echo $_GET['title'];?>">

虽然不确定这是否是您想要做的,但这样的 URL 看起来很丑陋.当然,重写会很好.

Not sure if that´s what you want to do though, the URL looks pretty ugly that way. Rewrite would be nice, of course.

您可能还想尝试诸如 prerender.io 之类的东西,但我不确定它是否会处理动态 og 标签.

You also may want to try something like prerender.io, but i am not sure if it will handle dynamic og tags.

这篇关于动态 Facebook Open Graph 标签可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆