WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. gotmedia
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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:

    <?php
      the_post_thumbnail(
        'full',
        array(
            '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:

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

    I hope that this helps!

  3. gotmedia
    Member
    Posted 1 year ago #

    Actually, the first code was PERFECT! Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic