Support » Plugin: AMP » logo and image are missing from AMP page

  • Resolved y2011

    (@y2011)


    google scan complains about the AMP page

    logo – A value for the logo field is required.
    image – A value for the image field is required.

    see link here

Viewing 1 replies (of 1 total)
  • Thread Starter y2011

    (@y2011)

    I found the answer:

    for the logo, just upload a logo image in appearance -> customize

    for the missing image, I had old posts with images inside but not “attached” the wordpress way.

    So I had to change the pluging code to support it.

    For anyone who’s interested:

    in plugins/amp/includes/class-amp-post-template.php

    
    	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 ) {       // get image from inside the post
                $image_url = (string) reset(simplexml_import_dom(DOMDocument::loadHTML($this->post->post_content))->xpath("//img/@src"));
                if (!empty($image_url)) {
                    list($image_width, $image_height) = getimagesize($image_url);
                    if ($image_width && $image_height) {
                        if ($image_width < 696) {       // google require minimum width of 696  https://developers.google.com/search/docs/data-types/articles
                            $image_width = 696;
                            $image_height = intval($image_height * 696 / $image_width);
                        }
                        $post_image_meta = array(
                            '@type' => 'ImageObject',
                            'url' => $image_url,
                            'width' => $image_width,
                            'height' => $image_height,
                        );
                    }
                } else {
                    $post_image_meta = array(
                        '@type' => 'ImageObject',
                        'url' => 'https://www.your domain.co.il/sample-photo.jpg',
                        'width' => 960,
                        'height' => 720,
                    );
                }
    		}
    
    		if (!$post_image_meta) {
                $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;
    	}
    
Viewing 1 replies (of 1 total)
  • The topic ‘logo and image are missing from AMP page’ is closed to new replies.