How To Get Width and Height for main header image only
-
I am currently installing schema code into the image tags and I am running into some trouble.
I have got to a point where I can get the width and height to display correctly for the main header image, but because I have related images at the bottom of the post, it puts the wrong image size in those image tags.
Is there a better way to do this? Any help is much appreciated.
/* adds the schema width and height for image */ function add_opening_span_before_img_tags_with_schema(){ add_filter('post_thumbnail_html','add_big_beginning_to_thumbnail'); function add_big_beginning_to_thumbnail($thumb) { $image_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "entry-thumbnail cherry-thumb-l aligncenter large" ); $image_width = $image_data[1]; $image_height = $image_data[2]; $feat_image_url = wp_get_attachment_url( get_post_thumbnail_id() ); $thumb = str_replace('<img', '<span itemprop="image" itemscope itemtype="https://schema.org/ImageObject"><meta itemprop="width" content="' . $image_width . '" ><meta itemprop="height" content="' . $image_height . '"><meta itemprop="url" content="' . $feat_image_url . '"><img', $thumb); return $thumb; } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How To Get Width and Height for main header image only’ is closed to new replies.