The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Schema.org: Editing the_post_thumbnail code? (3 posts)

  1. gotmedia
    Posted 3 years ago #

    Hi there,

    I'm working with this code:
    <?php the_post_thumbnail('full'); ?>

    What I'm trying to do is wrap it in a this tag: <img> because I want to add Structured Data Markup like so:

    <img itemprop="image" class="alignright size-full wp-image-753" alt="" src="image.jpg"/>

    Does anybody know how to do this?

  2. bencaplan
    Posted 3 years ago #

    Hi gotmedia,

    If I understand your question correctly, you are interested in adding the itemprop="image" portion? The function the_post_thumbnail() takes a second argument that allows you to pass in an array of HTML attributes. Thus to create this you could write the following:

            'itemprop' => 'image',
            'class' => 'alignright size-full wp-image-753',
            'alt' => 'image.jpg'

    If I am not understanding you correctly, and you are interested in using the new html 5 image tag or something else then you can always query for just the image src like so:

      $imageUrl = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );

    I hope that this helps!

  3. gotmedia
    Posted 3 years ago #

    Actually, the first code was PERFECT! Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic