简体   繁体   English

如何将tumblr og:image更改为至少200x200?

[英]How can I change a tumblr og:image to be at least 200x200?

I'm trying to help my friend with his tumblr blog since I know code and he doesn't. 我正在尝试通过他的tumblr博客帮助我的朋友,因为我知道代码,但他不知道。 Facebook Open Graph requires that an og:image be at least 200x200 to display the image when you link to your site, but tumblr forces an icon of 128x128 on your home page, so Facebook won't correctly link to your picture. Facebook Open Graph要求og:链接到网站时显示图像的大小必须至少为200x200,但tumblr会在首页上强制使用一个128x128的图标,因此Facebook无法正确链接到您的图片。

For example, visit Facebook's Object Debugger for his site and you can see there is a warning saying 例如,访问他的网站的 Facebook对象调试器,您会看到警告说

Provided og:image is not big enough. og:image不够大。 Please use an image that's at least 200x200 px. 请使用至少200x200像素的图像。 Image ' http://24.media.tumblr.com/7058d8a59658ff7e39e8ee83a8a72fc9/tumblr_n2ho09BYPS1sej21so1_500.jpg ' will be used instead. 图片' http://24.media.tumblr.com/7058d8a59658ff7e39e8ee83a8a72fc9/tumblr_n2ho09BYPS1sej21so1_500.jpg '将被代替。

I tried writing a jQuery function that should change the value of his og:image on his site, but it almost seems as if tumblr later goes in and changes the code after I have made my changes. 我尝试编写一个jQuery函数,该函数应该更改他的og:image在他的网站上的值,但似乎tumblr稍后加入并在进行更改后更改了代码。 Below is my code: 下面是我的代码:

<script>
$( document ).ready(function() {
    var metas = document.head.getElementsByTagName("meta");
    for (var i=0; i<metas.length;i++)
    {
        if(metas[i].getAttribute("property"))
            console.log(metas[i].getAttribute("property"));
        if(metas[i].getAttribute("property") == "og:image")
        {
            console.log("GOT IT!");
            metas[i].setAttribute("content", "http://25.media.tumblr.com/avatar_8c69b027eab0_512.png");
            console.log(metas[i].getAttribute("content"));
        }
    }
});
</script>

It seems to print out everything like how I would expect it to, but when I go to his site and view his source code, it keeps the old value for his og:image and not the new one that I set. 似乎可以像我期望的那样打印出所有内容,但是当我转到他的站点并查看他的源代码时,它保留了他的og:image的旧值,而不是我设置的新值。

You can go to his site and view the console to see that my code is printing out the expected results, but the og:image is not getting updated when you view the source code. 您可以转到他的站点并查看控制台,以查看我的代码正在打印出预期的结果,但是在查看源代码时og:image并未得到更新。

Javascript does not get executed when facebook reads the page for posting to its site. 当Facebook读取要发布到其网站的页面时,Javascript不会执行。 The jQuery gets ignored, so its going to grab the first large image on the page. jQuery被忽略,因此它将获取页面上的第一个大图像。

If you are just setting to the avatar. 如果您只是设置为头像。 why not just hardcode the link in the tumblr theme HTML? 为什么不只是硬编码tumblr主题HTML中的链接?

<meta property="og:image" content="http://25.media.tumblr.com/avatar_8c69b027eab0_512.png"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM