{"id":289,"date":"2026-06-19T10:56:59","date_gmt":"2026-06-19T10:56:59","guid":{"rendered":"https:\/\/tools.dwiyanti.com\/blog\/?p=289"},"modified":"2026-06-19T11:06:44","modified_gmt":"2026-06-19T11:06:44","slug":"schema-blogposting-web-dwiyanti-com","status":"publish","type":"post","link":"https:\/\/tools.dwiyanti.com\/blog\/schema-blogposting-web-dwiyanti-com","title":{"rendered":"Schema BlogPosting web DwiYanti.com"},"content":{"rendered":"<pre style=\"white-space:pre-wrap;\"><code>\nSCHEMA BLOGPOSTING DENGAN MENAMPILKAN SEMUA IMAGE YANG ADA DI <code>&lt?php the_content(); ?&gt<\/code>\nTAPI CODE IMAGE DI SEKITAR H1 TIDAK AKAN MUNCUL\n\n\n\/\/ SCHEMA BLOGPOSTING \nfunction add_blogposting_schema() {\n    if (!is_single()) {\n        return;\n    }\n    \n    global $post;\n    \n    \/\/ ========== DATA DASAR ==========\n    $title = get_the_title($post);\n    $url = get_permalink($post);\n    $published = get_the_date('c', $post);\n    $modified = get_the_modified_date('c', $post);\n    $description = get_optimized_meta_description(); \/\/ Dari fungsi yang sudah ada\n    $site_icon = get_site_icon_url();\n    \n    \/\/ ========== AMBIL SEMUA GAMBAR (UNIVERSAL) ==========\n    $images = [];\n    \n    \/\/ 1. Featured Image (dengan width\/height real)\n    if (has_post_thumbnail($post->ID)) {\n        $image_id = get_post_thumbnail_id($post->ID);\n        $image_url = wp_get_attachment_image_url($image_id, 'full');\n        $image_meta = wp_get_attachment_metadata($image_id);\n        \n        $images[] = [\n            \"@type\" => \"ImageObject\",\n            \"url\" => $image_url,\n            \"width\" => isset($image_meta['width']) ? $image_meta['width'] : 1200,\n            \"height\" => isset($image_meta['height']) ? $image_meta['height'] : 630\n        ];\n    }\n    \n    \/\/ 2. Ambil SEMUA gambar dari konten (tanpa batas 3)\n    $content = get_post_field('post_content', $post->ID);\n    preg_match_all('\/<img[^>]+src=[\"\\']([^\"\\']+)[\"\\']\/i', $content, $matches);\n    \n    if (!empty($matches[1])) {\n        foreach ($matches[1] as $img_url) {\n            \/\/ Hindari duplikat dengan featured image\n            $is_duplicate = false;\n            foreach ($images as $img) {\n                if ($img['url'] === $img_url) {\n                    $is_duplicate = true;\n                    break;\n                }\n            }\n            \n            if (!$is_duplicate) {\n                $images[] = [\n                    \"@type\" => \"ImageObject\",\n                    \"url\" => $img_url,\n                    \"width\" => 1200,\n                    \"height\" => 630\n                ];\n            }\n        }\n    }\n    \n    \/\/ 3. Fallback jika tidak ada gambar sama sekali\n    if (empty($images)) {\n        $images[] = [\n            \"@type\" => \"ImageObject\",\n            \"url\" => \"https:\/\/dwiyanti.com\/wp-content\/themes\/lifestyle\/assets\/images\/DwiYanti.png\",\n            \"width\" => 1200,\n            \"height\" => 630\n        ];\n    }\n    \n    \/\/ ========== DETEKSI KATEGORI UNTUK ABOUT ==========\n    $article_type = 'Article';\n    $primary_category = '';\n    $categories = get_the_category();\n    if (!empty($categories)) {\n        $primary_category = $categories[0]->name;\n        $cat_lower = strtolower($primary_category);\n        \n        if (in_array($cat_lower, ['beauty', 'skincare', 'makeup'])) {\n            $article_type = 'BeautyTips';\n        } elseif (in_array($cat_lower, ['health', 'wellness', 'fitness'])) {\n            $article_type = 'HealthTopic';\n        } elseif (in_array($cat_lower, ['lifestyle', 'travel', 'fashion'])) {\n            $article_type = 'LifestyleArticle';\n        }\n    }\n    \n    \/\/ ========== BANGUN SCHEMA ==========\n    $schema = [\n        \"@context\" => \"https:\/\/schema.org\",\n        \"@graph\" => [\n            [\n                \"@type\" => \"BlogPosting\",\n                \"headline\" => $title,\n                \"description\" => $description,\n                \"mainEntityOfPage\" => [\n                    \"@type\" => \"WebPage\",\n                    \"@id\" => $url\n                ],\n                \"author\" => [\n                    \"@type\" => \"Person\",\n                    \"name\" => \"Dwi Yanti\",\n                    \"@id\" => \"https:\/\/me.dwiyanti.com\/#dwi-yanti\"\n                ],\n                \"publisher\" => [\n                    \"@type\" => \"Organization\",\n                    \"@id\" => \"https:\/\/dwiyanti.com\/#organization\",\n                    \"name\" => \"Dwi Yanti SEO\",\n                    \"alternateName\" => \"Dwi Yanti SEO Specialist & Technical SEO Strategist\",\n                    \"logo\" => [\n                        \"@type\" => \"ImageObject\",\n                        \"url\" => $site_icon\n                    ]\n                ],\n                \"datePublished\" => $published,\n                \"dateModified\" => $modified,\n                \"image\" => $images\n            ]\n        ]\n    ];\n    \n    \/\/ Tambahkan 'about' untuk kategori Health\n    if ($article_type === 'HealthTopic' && !empty($primary_category)) {\n        $schema[\"@graph\"][0]['about'] = [\n            '@type' => 'MedicalCondition',\n            'name' => $primary_category\n        ];\n    }\n    \n    \/\/ ========== OUTPUT ==========\n    echo '<script type=\"application\/ld+json\">' . \"\\n\";\n    echo wp_json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);\n    echo \"\\n\" . '<\/script>' . \"\\n\";\n}\nadd_action('wp_head', 'add_blogposting_schema');\n\/\/ END Schema Markup\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SCHEMA BLOGPOSTING DENGAN MENAMPILKAN SEMUA IMAGE YANG ADA DI &#038;lt?php the_content(); ?&#038;gt TAPI CODE IMAGE DI SEKITAR H1 TIDAK AKAN MUNCUL \/\/ SCHEMA BLOGPOSTING function add_blogposting_schema() { if (!is_single()) { return; } global $post; \/\/ ========== DATA DASAR ========== $title = get_the_title($post); $url = get_permalink($post); $published = get_the_date(&#8216;c&#8217;, $post); $modified = get_the_modified_date(&#8216;c&#8217;, $post); $description = [&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-289","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/289","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=289"}],"version-history":[{"count":5,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/289\/revisions"}],"predecessor-version":[{"id":296,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/289\/revisions\/296"}],"wp:attachment":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/media?parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/categories?post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/tags?post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}