Request to amend the code to work on my site code on WordPress?

Question
  /**
 * Adds schema information to WordPress generated image tag.
 */
function stiver1_wp_image_schema_attributes( $attr, $attachment, $size ) {
    $is_edit = isset( $_GET['context'] ) ? 'edit' === $_GET['context'] : '';
    if ( $is_edit ) {
        return $attr;
    }
    $attachment_id = isset( $attachment->ID ) ? $attachment->ID : 0;
    if ( ! $attachment_id ) {
        return $attr;
    }
    $kora_image = wp_get_attachment_image_src( $attachment_id, $size );
    echo '<span itemprop="image" itemscope itemtype="https://schema.org/ImageObject">';
    echo '<meta itemprop="url" content="' . esc_url( $kora_image[0] ) . '">';
    echo '<meta itemprop="width" content="' . esc_attr( $kora_image[1] ) . '">';
    echo '<meta itemprop="height" content="' . esc_attr( $kora_image[2] ) . '">';
    echo '</span>';
    $attr['itemprop'] = 'image';
    return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'stiver1_wp_image_schema_attributes', 10, 3 );
0
kora12 8 months 2020-12-10T04:10:25-05:00 0 Answers 7 views 0

Leave an answer

Browse
Browse