{"id":320,"date":"2026-06-29T04:41:32","date_gmt":"2026-06-29T04:41:32","guid":{"rendered":"https:\/\/tools.dwiyanti.com\/blog\/?p=320"},"modified":"2026-06-29T04:41:32","modified_gmt":"2026-06-29T04:41:32","slug":"schema-website-simple","status":"publish","type":"post","link":"https:\/\/tools.dwiyanti.com\/blog\/schema-website-simple","title":{"rendered":"Schema Website simple"},"content":{"rendered":"<pre style=\"white-space:pre-wrap;\">\n\nSCHEMA WEBSITE SUPER SIMPLE TAPI RUN\n\/**\n * Schema Website Image - KHUSUS FRONTPAGE\n * Ambil SEMUA gambar dari halaman utama\n * Versi Sederhana - PASTI JALAN\n *\/\nfunction add_frontpage_schema_simple() {\n    \/\/ Hanya di frontpage\n    if (!is_front_page()) {\n        return;\n    }\n    \n    $images = array();\n    \n    \/\/ === AMBIL GAMBAR DARI 6 POST TERBARU ===\n    $latest_posts = new WP_Query(array(\n        'posts_per_page' => 6,\n        'post_status' => 'publish'\n    ));\n    \n    if ($latest_posts->have_posts()) {\n        while ($latest_posts->have_posts()) {\n            $latest_posts->the_post();\n            $post_id = get_the_ID();\n            \n            \/\/ Featured image\n            if (has_post_thumbnail($post_id)) {\n                $thumb = get_the_post_thumbnail_url($post_id, 'full');\n                if ($thumb) {\n                    $images[] = $thumb;\n                }\n            }\n            \n            \/\/ Gambar dari konten (jika tidak ada featured)\n            $content = get_post_field('post_content', $post_id);\n            preg_match('\/<img[^>]+src=\"([^\"]+)\"\/i', $content, $matches);\n            if (!empty($matches[1])) {\n                $images[] = $matches[1];\n            }\n        }\n        wp_reset_postdata();\n    }\n    \n    \/\/ === FALLBACK: Logo Website ===\n    if (empty($images)) {\n        $logo_id = get_theme_mod('custom_logo');\n        if ($logo_id) {\n            $images[] = wp_get_attachment_image_url($logo_id, 'full');\n        } else {\n            \/\/ Gambar default\n            $images[] = get_template_directory_uri() . '\/wp-content\/themes\/lifestyle\/assets\/images\/DwiYanti.jpeg';\n        }\n    }\n    \n    \/\/ === HAPUS DUPLIKAT ===\n    $images = array_unique($images);\n    \n    \/\/ === OUTPUT SCHEMA ===\n    ?>\n    <script type=\"application\/ld+json\">\n    {\n      \"@context\": \"https:\/\/schema.org\",\n      \"@type\": \"WebSite\",\n      \"name\": \"<?php echo esc_js(get_bloginfo('name')); ?>\",\n      \"url\": \"<?php echo esc_url(home_url('\/')); ?>\",\n      \"image\": [\n        <?php \n        $total = count($images);\n        foreach ($images as $index => $url): \n        ?>\n        {\n          \"@type\": \"ImageObject\",\n          \"url\": \"<?php echo esc_url($url); ?>\"\n        }<?php echo ($index < $total - 1) ? ',' : '' ?>\n        <?php endforeach; ?>\n      ]\n    }\n    <\/script>\n    <?php\n}\nadd_action('wp_head', 'add_frontpage_schema_simple');\n<\/pre>","protected":false},"excerpt":{"rendered":"SCHEMA WEBSITE SUPER SIMPLE TAPI RUN \/** * Schema Website Image &#8211; KHUSUS FRONTPAGE * Ambil SEMUA gambar dari halaman utama * Versi Sederhana &#8211; PASTI JALAN *\/ function add_frontpage_schema_simple() { \/\/ Hanya di frontpage if (!is_front_page()) { return; } $images = array(); \/\/ === AMBIL GAMBAR DARI 6 POST TERBARU === $latest_posts = new [&hellip;]","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-320","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/320","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=320"}],"version-history":[{"count":0,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"wp:attachment":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}