图像丢失且需要 - Wordpress AMP 结构不添加图像属性 [英] Image missing and required - Wordpress AMP Structure doesn't add Image attribute

查看:18
本文介绍了图像丢失且需要 - Wordpress AMP 结构不添加图像属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Google 的结构化数据测试工具验证我的 wordpress 帖子时,我收到以下错误:

When validating my wordpress posts using Google's Structured Data Testing Tool, I get the following error:

"Image: missing and required"

我安装了官方 wordpress AMP 插件,它为我生成了 AMP 页面.问题在于它不流行 BlogPosting 的图像"属性.

I have the official wordpress AMP plugin installed that generated the AMP pages for me. The problem is that it doesn't popular the "image" attribute for BlogPosting.

在插件中有一个我认为应该生成它的代码,但它没有在任何地方运行:

In the plugin there is a code that I think should generate it, but it's not running anywhere:

private function get_post_image_metadata() {
    $post_image_meta = null;
    $post_image_id = false;

    if ( has_post_thumbnail( $this->ID ) ) {
        $post_image_id = get_post_thumbnail_id( $this->ID );
    } else {
        $attached_image_ids = get_posts( array(
            'post_parent' => $this->ID,
            'post_type' => 'attachment',
            'post_mime_type' => 'image',
            'posts_per_page' => 1,
            'orderby' => 'menu_order',
            'order' => 'ASC',
            'fields' => 'ids',
            'suppress_filters' => false,
        ) );

        if ( ! empty( $attached_image_ids ) ) {
            $post_image_id = array_shift( $attached_image_ids );
        }
    }

    if ( ! $post_image_id ) {
        return false;
    }

    $post_image_src = wp_get_attachment_image_src( $post_image_id, 'full' );

    if ( is_array( $post_image_src ) ) {
        $post_image_meta = array(
            '@type' => 'ImageObject',
            'url' => $post_image_src[0],
            'width' => $post_image_src[1],
            'height' => $post_image_src[2],
        );
    }

    return $post_image_meta;
}

如何使用此 AMP WordPress 插件为每个帖子填充图像标签?我希望页面通过结构化数据测试工具,这样他也可以通过 AMP 验证.

How can I populate the image tag for each post using this AMP WordPress plugin? I want the page to pass the Structured Data Testing Tool, so he can pass the AMP validation as well.

更新:图片未显示的原因是帖子中没有嵌入图片.有没有办法在没有默认图像的情况下放置默认图像,以便通过 AMP/Schema 验证.

Update: the reason that the image is not showing is because there is not embedded image in the post. Is there a way to put a default image in case there isn't one, so it will pass the AMP/Schema validation.

推荐答案

为了符合 AMP HTML 规范,您不必使用 Schema.org 结构化数据.

For conforming to the AMP HTML Specification, you don’t have to use Schema.org structured data.

如果 Google SDTT 说某个属性缺失且需要",这并不意味着 AMP 或 Schema.org 需要它.仅意味着 Google 不会为您的网页显示其中一项 Google 搜索结果功能(例如 Rich Snippets).

If the Google SDTT says that a property is "missing and required", it does not mean that it’s required by AMP or Schema.org. It only means that Google won’t show one of their Google Search results features (like Rich Snippets) for your page.

例如,有 使用 AMP 的热门故事 功能:链接到 AMP 页面的轮播图,显示每个页面的图像.这就是 Google 需要 Schema.org 图像的原因 此功能的属性(对于文章).但是,不为您的文章提供图片完全没有问题,发生"的唯一事情是您的页面没有机会出现在头条新闻"轮播中.

For example, there’s the Top Stories with AMP feature: a carousel that links to AMP pages, showing an image from each page. That’s why Google requires the Schema.org image property for this feature (for articles). But it’s perfectly fine not to provide an image for your article, the only thing that "happens" is that your page doesn’t get a chance to appear in that Top Stories carousel.

如果 is_array( $post_image_src ) 为 false,您当然可以使用默认图像(例如占位符)填充 $post_image_meta,但这很可能不是一个好方法想法:图像不相关,因此在 Google 搜索上搜索的用户不会发现它有用,因此 Google 搜索有兴趣不向他们的用户显示您的结果.(但如果以及以哪种方式实际情况是 SEO 问题,属于 Webmasters SE.)

You could of course populate $post_image_meta with a default image (e.g., a placeholder) if is_array( $post_image_src ) is false, but that’s very likely not a good idea: the image wouldn’t be relevant, so users searching on Google Search wouldn’t find it useful, so Google Search would have an interest not to show your result to their users. (But if and in which way that’s actually the case is an SEO issue, which belongs to Webmasters SE.)

这篇关于图像丢失且需要 - Wordpress AMP 结构不添加图像属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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