1

I've been stuck on this problem for a few days, so I thought its best to ask the community.

So my problem is this, I'm trying to share a post. The post is generated dynamically. I'm using the addthis.com sharing toolbox. I also installed the SEO plugin by netsti and added the component on header

Now when I want to share, the image doesn't load on first share. I need to scrape the information through Facebook debugger.

I want to know if there is anyway to make a

So I'd like to know if there's anyway to set up the meta og image on head with functions like onStart or onEnd

Thanks

4

1 回答 1

1

是的,为什么不可以在布局中添加自己的标签。

在您的<head>标签所在的布局文件或部分文件中,您可以定义类似这样的内容

    {% if fbImage %}
        <meta property="og:image" content="{{ fbImage }}" />            
    {% endif %}

现在在您的页面代码部分,您可以定义onStart方法并添加您的fbImage

function onStart(){    

    // or you can get file object from your post or record 
    // and get its absolute path and use it `getPath()`
    $imagePath = 'https://yoursite/image.jpeg';
    $this['fbImage'] = $imagePath; // image absolute path
}

通过这种方式,您告诉页面要在“og:image”标签中显示什么图像,并且为了安全起见,我们正在检查它的值,如果它未定义或我们在条件下使用空白,因此不会添加“og:image”标签。

如果有任何问题,请发表评论。

于 2017-11-22T11:46:56.763 回答