图片丢失且必填-Wordpress AMP Structure不添加“图片"属性 [英] Image missing and required - Wordpress AMP Structure doesn't add Image attribute

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

问题描述

使用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 image属性的原因针对此功能(针对文章).但是,最好不要为您的文章提供图片,唯一可以发生"的是,您的页面没有机会出现在热门故事"轮播中.

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问题属于网站管理员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 Structure不添加“图片"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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