{"id":284,"date":"2026-06-19T10:37:37","date_gmt":"2026-06-19T10:37:37","guid":{"rendered":"https:\/\/tools.dwiyanti.com\/blog\/?p=284"},"modified":"2026-06-19T10:42:22","modified_gmt":"2026-06-19T10:42:22","slug":"schema-image-universal","status":"publish","type":"post","link":"https:\/\/tools.dwiyanti.com\/blog\/schema-image-universal","title":{"rendered":"Schema Image Universal"},"content":{"rendered":"<pre style=\"white-space:pre-wrap\">\n\n\n\/* Schema Image Object hanya muncul di post dan Page *\/\nfunction add_all_images_schema_universal() {\n    \/\/ Cek apakah ini post ATAU page\n    if (!is_page()) {\n        return;\n    }\n    \n    \/\/ Ambil semua gambar dari konten\n    $content = get_post_field('post_content', get_the_ID());\n    preg_match_all('\/<img[^>]+src=\"([^\"]+)\"\/i', $content, $matches);\n    \n    if (empty($matches[1]) && !has_post_thumbnail()) {\n        return;\n    }\n    \n    $images = array();\n    \n    \/\/ Featured image\n    if (has_post_thumbnail()) {\n        $images[] = array(\n            'url' => wp_get_attachment_image_url(get_post_thumbnail_id(), 'full'),\n            'type' => 'featured'\n        );\n    }\n    \n    \/\/ Gambar dari konten\n    foreach ($matches[1] as $src) {\n        \/\/ Hindari duplikasi\n        $is_duplicate = false;\n        foreach ($images as $img) {\n            if ($img['url'] === $src) {\n                $is_duplicate = true;\n                break;\n            }\n        }\n        if (!$is_duplicate) {\n            $images[] = array(\n                'url' => $src,\n                'type' => 'content'\n            );\n        }\n    }\n    \n    \/\/ Tentukan schema type berdasarkan tipe konten\n    $schema_type = is_page() ? 'WebPage' : 'Website';\n    ?>\n    <script type=\"application\/ld+json\">\n    {\n      \"@context\": \"https:\/\/schema.org\",\n      \"@type\": \"<?php echo $schema_type; ?>\",\n      \"headline\": \"<?php echo esc_js(get_the_title()); ?>\",\n      \"image\": [\n        <?php foreach ($images as $index => $img): ?>\n        {\n          \"@type\": \"ImageObject\",\n          \"url\": \"<?php echo esc_url($img['url']); ?>\"\n        }<?php echo ($index < count($images) - 1) ? ',' : '' ?>\n        <?php endforeach; ?>\n      ]\n    }\n    <\/script>\n    <?php\n}\nadd_action('wp_head', 'add_all_images_schema_universal');\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/* Schema Image Object hanya muncul di post dan Page *\/ function add_all_images_schema_universal() { \/\/ Cek apakah ini post ATAU page if (!is_page()) { return; } \/\/ Ambil semua gambar dari konten $content = get_post_field(&#8216;post_content&#8217;, get_the_ID()); preg_match_all(&#8216;\/]+src=&#8221;([^&#8221;]+)&#8221;\/i&#8217;, $content, $matches); if (empty($matches[1]) &#038;&#038; !has_post_thumbnail()) { return; } $images = array(); \/\/ Featured image if (has_post_thumbnail()) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-284","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/comments?post=284"}],"version-history":[{"count":4,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":288,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/284\/revisions\/288"}],"wp:attachment":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}