那是因为 append 方法不会在已经定义的图像上添加 og:image。append 方法会将下一个 og:image 附加到已经定义的 og:image 中,最终得到一个数组。同样,如果您选择 prepend,这会将您的新 og:image 标签添加到您已经定义的标签之前。
我认为您真正想要的是最初设置属性,而不是附加它。
$hm = $serviceManager->get('ViewHelperManager')->get('headMeta');
$hm->setProperty('og:image', '/images/opengraph/1.jpg');
然后稍后:
$hm->setProperty('og:image', '/images/opengraph/2.jpg');
甚至更晚:
$hm->setProperty('og:image', '/images/opengraph/2.jpg');
If you absolutely want to blow away the list, as a last resort you can see this link: Zend Framework: Clearing/Resetting HeadLink, HeadMeta, HeadScript, HeadStyle and HeadTitle based on ZF1 but looking at the ZF2 code appears to be the same.
Perhaps a better solution to the overall challenge is not eagerly set the og:image's in the module, but to always set them as late as possible so you are not in this situation.