{"id":387,"date":"2026-07-20T12:33:56","date_gmt":"2026-07-20T12:33:56","guid":{"rendered":"https:\/\/tools.dwiyanti.com\/blog\/?p=387"},"modified":"2026-07-20T12:33:56","modified_gmt":"2026-07-20T12:33:56","slug":"schema-website-blog","status":"publish","type":"post","link":"https:\/\/tools.dwiyanti.com\/blog\/schema-website-blog","title":{"rendered":"Schema Website Blog"},"content":{"rendered":"<pre style=\"white-space:pre-wrap;\">\nSCHEMA WEBSITE BLOG DWIYANTI.COM DENGAN KEYWORD DIAMBIL DARI ID\n---\n\/\/ SCHEMA WEBSITE KHUSUS FRONTPAGE - Hanya tampil di homepage\nadd_action('wp_head', 'add_homepage_website_itemlist_schema');\nfunction add_homepage_website_itemlist_schema() {\n\n    \/\/ HANYA tampil di frontpage\n    if (!is_home() && !is_front_page()) {\n        return;\n    }\n\n    global $post;\n\n    $url = home_url();\n    $site_name = get_optimized_meta_title();\n    $description = get_optimized_meta_description();\n\n    \/\/ === KUMPULKAN GAMBAR DARI FRONTPAGE ===\n    $images = [];\n    $content = isset($post->post_content) ? $post->post_content : '';\n\n    \/\/ 1. Ambil dari tag <img>\n    preg_match_all('\/<img[^>]+src=[\"\\']([^\"\\']+)[\"\\']\/i', $content, $matches);\n    if (!empty($matches[1])) {\n        foreach ($matches[1] as $img_url) {\n            $images[] = [\n                \"@type\" => \"ImageObject\",\n                \"url\" => $img_url,\n                \"width\" => 1200,\n                \"height\" => 630\n            ];\n        }\n    }\n\n    \/\/ 2. Ambil dari background-image CSS\n    preg_match_all('\/background-image:\\s*url\\([\\'\"]?([^\\'\"]+)[\\'\"]?\\)\/i', $content, $bg_matches);\n    if (!empty($bg_matches[1])) {\n        foreach ($bg_matches[1] as $img_url) {\n            $images[] = [\n                \"@type\" => \"ImageObject\",\n                \"url\" => $img_url,\n                \"width\" => 1200,\n                \"height\" => 630\n            ];\n        }\n    }\n\n    \/\/ 3. Featured image (jika homepage punya)\n    if (has_post_thumbnail()) {\n        $images[] = [\n            \"@type\" => \"ImageObject\",\n            \"url\" => wp_get_attachment_image_url(get_post_thumbnail_id(), 'full'),\n            \"width\" => 1200,\n            \"height\" => 630\n        ];\n    }\n\n    \/\/ 4. Fallback: Site icon atau logo\n    if (empty($images)) {\n        $site_icon = get_site_icon_url();\n        if ($site_icon) {\n            $images[] = [\n                \"@type\" => \"ImageObject\",\n                \"url\" => $site_icon,\n                \"width\" => 512,\n                \"height\" => 512\n            ];\n        } else {\n            \/\/ Fallback terakhir\n            $images[] = [\n                \"@type\" => \"ImageObject\",\n                \"url\" => \"https:\/\/dwiyanti.com\/wp-content\/themes\/lifestyle\/assets\/images\/DwiYanti.jpeg\",\n                \"width\" => 1200,\n                \"height\" => 630\n            ];\n        }\n    }\n\n    \/\/ Batasi maksimal 10 gambar\n    $images = array_slice($images, 0, 10);\n\n    \/\/ Ambil 6 postingan terbaru\n    $recent_posts = get_posts(array(\n        'numberposts' => 6,\n        'post_status' => 'publish',\n        'post_type'   => 'post'\n    ));\n\n    \/\/ Siapkan array itemListElement untuk blog posts\n    $item_list = array();\n    $position = 1;\n\n    foreach ($recent_posts as $post) {\n        setup_postdata($post);\n\n        \/\/ ===== AMBIL GAMBAR DARI KONTEN (PRIORITAS UTAMA) =====\n        $post_image = '';\n        $content = get_post_field('post_content', $post->ID);\n\n        \/\/ Cari gambar pertama dari konten\n        preg_match('\/<img.+src=[\\'\"]([^\\'\"]+)[\\'\"].*>\/i', $content, $matches);\n        if (! empty($matches[1])) {\n            $post_image = $matches[1];\n        }\n\n        \/\/ ===== FALLBACK 1: Jika tidak ada gambar di konten, ambil dari thumbnail\/feature image =====\n        if (empty($post_image)) {\n            $thumbnail_id = get_post_thumbnail_id($post->ID);\n            if ($thumbnail_id) {\n                $thumbnail_url = wp_get_attachment_image_url($thumbnail_id, 'full');\n                if ($thumbnail_url) {\n                    $post_image = $thumbnail_url;\n                }\n            }\n        }\n\n        \/\/ ===== FALLBACK 2: Jika masih tidak ada, gunakan gambar default =====\n        if (empty($post_image)) {\n            $post_image = $site_url . '\/wp-content\/themes\/lifestyle\/assets\/images\/DwiYanti.jpeg';\n        }\n\n        \/\/ Buat ImageObject untuk setiap postingan\n        $image_object = array(\n            '@type' => 'ImageObject',\n            'url' => $post_image,\n            'width' => 800,\n            'height' => 600\n        );\n\n        \/\/ Coba dapatkan dimensi gambar sebenarnya (jika gambar lokal)\n        if (strpos($post_image, home_url()) !== false) {\n            $attachment_id = attachment_url_to_postid($post_image);\n            if ($attachment_id) {\n                $metadata = wp_get_attachment_metadata($attachment_id);\n                if ($metadata && isset($metadata['width']) && isset($metadata['height'])) {\n                    $image_object['width'] = $metadata['width'];\n                    $image_object['height'] = $metadata['height'];\n                }\n            }\n        }\n        \/\/ ===== END AMBIL GAMBAR =====\n\n        $item_list[] = array(\n            '@type' => 'ListItem',\n            'position' => $position,\n            'url' => get_permalink($post->ID),\n            'name' => get_the_title($post->ID),\n            'description' => wp_trim_words(get_the_excerpt($post), 20),\n            'image' => $image_object\n        );\n        $position++;\n    }\n    wp_reset_postdata();\n\n    \/\/ Keyword dengan tambahan dari ID atribut HTML - Support Frontpage\/Home\n    function get_schema_keywords($post_id = null)\n    {\n\n        $keywords = [];\n\n        \/\/ Cek apakah ini frontpage\/home\n        if (is_front_page() || is_home()) {\n\n            \/\/ 1. Ambil semua post\/page yang muncul di frontpage\n            \/\/ Misal: ambil dari loop utama atau dari section builder\n\n            \/\/ Opsi A: Jika menggunakan loop utama WordPress\n            if (have_posts()) {\n                while (have_posts()) {\n                    the_post();\n                    $current_id = get_the_ID();\n                    $keywords = array_merge($keywords, get_keywords_from_content($current_id));\n                }\n                rewind_posts(); \/\/ Reset loop\n            }\n\n            \/\/ Opsi B: Jika menggunakan page builder (Elementor, Gutenberg, dll)\n            \/\/ Ambil konten dari halaman frontpage yang sedang aktif\n            $frontpage_id = get_option('page_on_front');\n            if ($frontpage_id) {\n                $keywords = array_merge($keywords, get_keywords_from_content($frontpage_id));\n            }\n\n            \/\/ Opsi C: Ambil dari semua post type yang ditampilkan di home\n            $all_posts = get_posts(array(\n                'posts_per_page' => -1,\n                'post_type' => array('post', 'page', 'custom_post_type'), \/\/ Sesuaikan\n                'post_status' => 'publish'\n            ));\n\n            foreach ($all_posts as $post) {\n                $keywords = array_merge($keywords, get_keywords_from_content($post->ID));\n            }\n        } else {\n            \/\/ Jika bukan frontpage, gunakan fungsi original\n            $keywords = get_keywords_from_content($post_id);\n        }\n\n        \/\/ Hapus duplikat dan kosong\n        $keywords = array_filter(array_unique($keywords));\n\n        return implode(', ', $keywords);\n    }\n\n    \/\/ Fungsi bantuan untuk mengambil keywords dari satu post\/page\n    function get_keywords_from_content($post_id)\n    {\n        $keywords = [];\n\n        \/\/ 1. Prioritaskan tag\n        $tags = wp_get_post_tags($post_id);\n        foreach ($tags as $tag) {\n            $keywords[] = $tag->name;\n        }\n\n        \/\/ 2. Jika tidak ada tag, gunakan kategori\n        if (empty($keywords)) {\n            $categories = get_the_category($post_id);\n            foreach ($categories as $category) {\n                $keywords[] = $category->name;\n            }\n        }\n\n        \/\/ 3. Ambil ID dari konten post\n        $content = get_post_field('post_content', $post_id);\n        $id_keywords = extract_ids_from_content($content);\n\n        \/\/ Gabungkan dengan keywords yang sudah ada\n        if (!empty($id_keywords)) {\n            $keywords = array_merge($keywords, $id_keywords);\n        }\n\n        return $keywords;\n    }\n\n    \/\/ Fungsi bantuan keyword untuk mengekstrak ID dari HTML\n    function extract_ids_from_content($content)\n    {\n        $ids = [];\n\n        \/\/ Pattern untuk mencari semua atribut id\n        preg_match_all('\/\\bid=[\"\\']([^\"\\']*)[\"\\']\/', $content, $matches);\n\n        if (!empty($matches[1])) {\n            foreach ($matches[1] as $id) {\n                \/\/ Bersihkan ID (hilangkan spasi, karakter aneh)\n                $clean_id = trim($id);\n                if (!empty($clean_id)) {\n                    $ids[] = $clean_id;\n                }\n            }\n        }\n\n        return $ids;\n    }\n\n    \/\/ === BUAT SCHEMA ===\n    $schema_website = array(\n        \"@context\"         => \"https:\/\/schema.org\",\n        \"@type\"            => \"WebSite\",\n        \"@id\"              => $url . \"#website\",\n        \"url\"              => $url,\n        \"name\"             => $site_name,\n        \"alternateName\"    => [\"DwiYanti\", \"dwynti\", \"dwee\", \"Dwi Yanti\"],\n        \"description\"      => $description,\n        \"inLanguage\"       => \"id-ID\",\n        \"image\"            => $images,\n        \"keywords\"         => get_schema_keywords(),\n        \"publisher\"        => [\n            \"@type\"         => \"Organization\",\n            \"@id\"           => $url . \"#organization\",\n            \"name\"          => \"Dwi Yanti SEO\",\n            \"alternateName\" => \"Dwi Yanti SEO Specialist and Technical SEO Strategist\",\n            \"url\"           => $url,\n            \"logo\"          => [\n                \"@type\"  => \"ImageObject\",\n                \"url\"    => get_site_icon_url() ?: \"https:\/\/dwiyanti.com\/wp-content\/themes\/lifestyle\/assets\/images\/DwiYanti.jpeg\",\n                \"width\"  => 512,\n                \"height\" => 512\n            ]\n        ],\n        \"potentialAction\" => [\n            \"@type\"        => \"SearchAction\",\n            \"target\"       => $url . \"\/?s={search_term_string}\",\n            \"query-input\"  => \"required name=search_term_string\"\n        ],\n        \"author\"  => [\n            \"@id\" => \"https:\/\/me.dwiyanti.com\/#dwi-yanti\"\n        ],\n        \"creator\" => [\n            \"@id\" => \"https:\/\/me.dwiyanti.com\/#dwi-yanti\"\n        ],\n        'mainEntity' => array(\n            '@type' => 'ItemList',\n            'itemListElement' => $item_list,\n            'numberOfItems' => count($recent_posts)\n        ),\n        \"about\" => [\n            [\n                \"@type\"  => \"Thing\",\n                \"name\"   => \"Search Engine Optimization\",\n                \"sameAs\" => \"https:\/\/en.wikipedia.org\/wiki\/Search_engine_optimization\" \/\/ Tautan Wikipedia untuk mempertegas entitas ke AI\n            ],\n            [\n                \"@type\"  => \"Thing\",\n                \"name\"   => \"SEO Specialist\",\n                \"sameAs\" => \"https:\/\/en.wikipedia.org\/wiki\/SEO_Specialist\"\n            ],\n            [\n                \"@type\"  => \"Thing\",\n                \"name\"   => \"Technical SEO\",\n                \"sameAs\" => \"https:\/\/en.wikipedia.org\/wiki\/Technical_SEO\"\n            ]\n        ]\n    );\n\n    echo '<script type=\"application\/ld+json\">' . \"\\n\";\n    echo json_encode($schema_website, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);\n    echo \"\\n\" . '<\/script>' . \"\\n\";\n}\n\/\/ END Schema Website + ItemList\n<\/pre>","protected":false},"excerpt":{"rendered":"SCHEMA WEBSITE BLOG DWIYANTI.COM DENGAN KEYWORD DIAMBIL DARI ID &#8212; \/\/ SCHEMA WEBSITE KHUSUS FRONTPAGE &#8211; Hanya tampil di homepage add_action(&#8216;wp_head&#8217;, &#8216;add_homepage_website_itemlist_schema&#8217;); function add_homepage_website_itemlist_schema() { \/\/ HANYA tampil di frontpage if (!is_home() &#038;&#038; !is_front_page()) { return; } global $post; $url = home_url(); $site_name = get_optimized_meta_title(); $description = get_optimized_meta_description(); \/\/ === KUMPULKAN GAMBAR DARI FRONTPAGE === [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-387","post","type-post","status-publish","format-standard","hentry","category-schema"],"_links":{"self":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/387","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=387"}],"version-history":[{"count":1,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/387\/revisions"}],"predecessor-version":[{"id":388,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/387\/revisions\/388"}],"wp:attachment":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/media?parent=387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/categories?post=387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/tags?post=387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}