بن ناصر بي اتش بي

الوسم: add attribute itemprop to post thumbnail

  • إضافة schema سكيما للصورة البارزة itemprop

    مرحبا
    أخي ، لقد قمت بتثبيت كود ولاكن أواجه مشكلة

    إنه يعمل بشكل جيد هنا

    https://k.top4top.io/p_1789l666i1.png

    https://l.top4top.io/p_1789p2c7b2.png

    https://a.top4top.io/p_1789fyyi53.png

    لكن المشكلة عندما أضع صورة للمقال الذي تم تحميله
    وكل شيء على ما يرام

    وعندما أنقر لإضافته لا تظهر الصورة

    لكنها لا تظهر عند النقر فوق إضافة صورة بارزة

    هناك شيء في الكود يمنع ذلك
    هاهو الكود

     * Adds schema information to WordPress generated image tag.
     */
    function yallagoal_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;
    	}
    	$yallagoal_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( $yallagoal_image[0] ) . '">';
    	echo '<meta itemprop="width" content="' . esc_attr( $yallagoal_image[1] ) . '">';
    	echo '<meta itemprop="height" content="' . esc_attr( $yallagoal_image[2] ) . '">';
    	echo '</span>';
    	$attr['itemprop'] = 'image';
    	return $attr;
    }
    add_filter( 'wp_get_attachment_image_attributes', 'yallagoal_wp_image_schema_attributes', 10, 3 );