ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php-图片丢失且必填-WordPress AMP结构未添加图片属性

2019-11-19 01:29:31  阅读:195  来源: 互联网

标签:schema-org amp-html wordpress-plugin wordpress php


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

"Image: missing and required"

我安装了正式的wordpress AMP插件,可以为我生成AMP页面.问题在于,它不流行BlogPosting的“ image”属性.

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

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验证.

更新:未显示图片的原因是帖子中没有嵌入图片.如果没有默认图像,是否有办法放置默认图像,因此它将通过AMP / Schema验证.

解决方法:

要符合AMP HTML Specification,您不必使用Schema.org结构化数据.

如果Google SDTT指出某个属性“缺失且必填”,则并不意味着AMP或Schema.org都需要该属性. Google不会在您的页面上显示only means,而不会显示其Google搜索结果功能之一(例如Rich Snippets).

例如,有一个Top Stories with AMP功能:轮播,链接到AMP页面,显示每个页面的图像.这就是为什么Google requires此功能的Schema.org图像属性(针对文章)的原因.但是,最好不要为您的文章提供图片,唯一可以“发生”的是,您的页面没有机会出现在“热门故事”轮播中.

如果is_array($post_image_src)为false,您当然可以使用默认图像(例如,占位符)填充$post_image_meta,但这不是一个好主意:该图像将不相关,因此在Google搜索中搜索的用户将不会找不到有用的内容,因此Google搜索有兴趣不向其用户显示您的结果. (但实际上是哪种情况以及哪种方式是SEO问题,属于Webmasters SE.)

标签:schema-org,amp-html,wordpress-plugin,wordpress,php
来源: https://codeday.me/bug/20191119/2032513.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有