{"id":383,"date":"2026-07-20T12:11:28","date_gmt":"2026-07-20T12:11:28","guid":{"rendered":"https:\/\/tools.dwiyanti.com\/blog\/?p=383"},"modified":"2026-07-20T12:11:29","modified_gmt":"2026-07-20T12:11:29","slug":"keyword-schema-webpage","status":"publish","type":"post","link":"https:\/\/tools.dwiyanti.com\/blog\/keyword-schema-webpage","title":{"rendered":"Keyword + Schema WebPage"},"content":{"rendered":"<pre style=\"white-space:pre-wrap;\">\nKEYWORD DI SCHEMA WEBPAGE DENGAN FIELD KEYWORD BLOG DWIYANTI.COM\n----\n\/\/ SCHEMA WEBPAGE\n\/\/ METABOX DI ADMIN\nfunction add_schema_keywords_metabox_webpage() {\n    add_meta_box(\n        'schema_keywords_metabox_webpage',\n        'Schema Keywords Manual',\n        'render_schema_keywords_metabox_webpage',\n        'page', \/\/ Untuk halaman (page)\n        'normal',\n        'default'\n    );\n}\nadd_action('add_meta_boxes', 'add_schema_keywords_metabox_webpage');\n\nfunction render_schema_keywords_metabox_webpage($post) {\n    wp_nonce_field('schema_keywords_nonce', 'schema_keywords_nonce_field');\n    $schema_keywords = get_post_meta($post->ID, '_schema_keywords_manual', true);\n    ?>\n    <p>\n        <label for=\"schema_keywords_manual\">\n            <strong>Masukkan Keywords untuk Schema WebPage (pisahkan dengan koma):<\/strong>\n        <\/label>\n    <\/p>\n    <p>\n        <input type=\"text\" \n               id=\"schema_keywords_manual\" \n               name=\"schema_keywords_manual\" \n               value=\"<?php echo esc_attr($schema_keywords); ?>\" \n               style=\"width: 100%; padding: 8px;\" \n               placeholder=\"Contoh: SEO, WordPress, Digital Marketing, Optimasi Website\">\n    <\/p>\n    <p class=\"description\">\n        <strong>Wajib diisi!<\/strong> Keywords ini akan digunakan untuk field \"keywords\" di schema WebPage.\n        Biarkan kosong jika ingin menggunakan tag\/kategori otomatis.\n    <\/p>\n    <?php\n}\n\n\/\/ ========== SIMPAN DATA METABOX ==========\nfunction save_schema_keywords_metabox_webpage($post_id) {\n    if (!isset($_POST['schema_keywords_nonce_field'])) {\n        return;\n    }\n    \n    if (!wp_verify_nonce($_POST['schema_keywords_nonce_field'], 'schema_keywords_nonce')) {\n        return;\n    }\n    \n    if (defined('DOING_AUTOSAVE') &#038;&#038; DOING_AUTOSAVE) {\n        return;\n    }\n    \n    if (!current_user_can('edit_post', $post_id)) {\n        return;\n    }\n    \n    if (isset($_POST['schema_keywords_manual'])) {\n        $keywords = sanitize_text_field($_POST['schema_keywords_manual']);\n        update_post_meta($post_id, '_schema_keywords_manual', $keywords);\n    }\n}\nadd_action('save_post', 'save_schema_keywords_metabox_webpage');\n\n\/\/ ========== FUNGSI UTAMA SCHEMA WEBPAGE ==========\nfunction add_webpage_schema() {\n    if (is_front_page() || is_home()) {\n        return; \/\/ Exit jika halaman Home\n    }\n\n    if (!is_page()) {\n        return;\n    }\n\n    global $post;\n\n    if ($post->post_title === 'Home' || $post->post_name === 'home') {\n        return;\n    }\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();\n    $site_icon = get_site_icon_url();\n    $site_url    = home_url();\n    $in_language = 'id-ID';\n\n    \/\/ ========== AMBIL SEMUA GAMBAR (UNIVERSAL) ==========\n    $images = [];\n    $primary_image = null;\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        $image_alt  = get_post_meta( $image_id, '_wp_attachment_image_alt', true );\n        $image_cap  = wp_get_attachment_caption( $image_id );\n\n        $image_data = [\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        $images[] = $image_data;\n        $primary_image = $image_data;\n    }\n\n    \/\/ 2. Ambil SEMUA gambar dari konten\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            $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                $image_data = [\n                    \"@type\" => \"ImageObject\",\n                    \"url\" => $img_url,\n                    \"width\" => 1200,\n                    \"height\" => 630\n                ];\n                $images[] = $image_data;\n\n                if ($primary_image === null) {\n                    $primary_image = $image_data;\n                }\n            }\n        }\n    }\n\n    \/\/ 3. Fallback jika tidak ada gambar sama sekali\n    if (empty($images)) {\n        $image_data = [\n            \"@type\" => \"ImageObject\",\n            \"url\" => \"https:\/\/dwiyanti.com\/wp-content\/themes\/lifestyle\/assets\/images\/DwiYanti.jpeg\",\n            \"width\" => 1200,\n            \"height\" => 630\n        ];\n        $images[] = $image_data;\n        $primary_image = $image_data;\n    }\n\n    if ($primary_image === null && !empty($images)) {\n        $primary_image = $images[0];\n    }\n\n    \/\/ ========== FUNGSI KEYWORDS (HANYA MANUAL) ==========\n    function get_schema_keywords($post_id) {\n        \/\/ HANYA ambil dari manual input\n        $manual_keywords = get_post_meta($post_id, '_schema_keywords_manual', true);\n        \n        if (!empty($manual_keywords)) {\n            return $manual_keywords;\n        }\n\n        \/\/ FALLBACK: Jika kosong, gunakan tag\n        $keywords = [];\n        $tags = wp_get_post_tags($post_id);\n        foreach ($tags as $tag) {\n            $keywords[] = $tag->name;\n        }\n\n        \/\/ 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        return implode(', ', array_unique($keywords));\n    }\n\n    \/\/ ========== FUNGSI MENTIONS ==========\n    function get_mentions($post_id) {\n        $mentions = [];\n        $tags = wp_get_post_tags($post_id);\n\n        foreach ($tags as $tag) {\n            $mentions[] = [\n                \"@type\" => \"Thing\",\n                \"name\" => $tag->name\n            ];\n        }\n\n        return $mentions;\n    }\n\n    \/\/ ========== FUNGSI ABOUT ==========\n    function get_about_topic($post_id) {\n        $categories = get_the_category($post_id);\n        if (!empty($categories)) {\n            return $categories[0]->name;\n        }\n        return \"Page\";\n    }\n\n    \/\/ ========== SCHEMA WEBPAGE ==========\n    $schema_webpage = [\n        \"@context\" => \"https:\/\/schema.org\",\n        \"@graph\" => [\n            [\n                \"@type\" => \"WebPage\",\n                \"@id\" => $url . \"#webpage\",\n                \"url\" => $url,\n                \"headline\" => $title,\n                \"description\" => $description,\n                'inLanguage'     => $in_language,\n                'isPartOf'       => [\n                    '@type' => 'WebSite',\n                    '@id'   => $site_url . '\/#website',\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 and Technical SEO Strategist\",\n                    \"logo\" => [\n                        \"@type\" => \"ImageObject\",\n                        \"url\" => $site_icon\n                    ]\n                ],\n                \"mainEntity\" => [\n                    \"@id\" => $url . \"#article\"\n                ],\n                \"image\" => $images,\n                \n                \/\/ ===== KEYWORDS: MANUAL =====\n                \"keywords\" => get_schema_keywords($post->ID),\n\n                \/\/ Speakable\n                'speakable' => [\n                    '@type'       => 'SpeakableSpecification',\n                    'cssSelector' => [\n                        'h1',\n                        '.post-content p:first-of-type',\n                        \".speakable-second\",\n                        \".speakable-last\"\n                    ]\n                ],\n\n                \/\/ ========== GEO OPTIMIZATION ==========\n                \"about\" => [\n                    \"@type\" => \"Thing\",\n                    \"@id\" => home_url('\/#seo'),\n                    \"name\" => get_about_topic($post->ID)\n                ],\n                \"mentions\" => get_mentions($post->ID),\n                \"text\" => wp_trim_words(\n                    wp_strip_all_tags($post->post_content),\n                    700,\n                    '...'\n                ),\n                \"potentialAction\" => [\n                    \"@type\"=>\"ReadAction\",\n                    \"target\"=>$url\n                ],\n                \"primaryImageOfPage\" => $primary_image\n            ]\n        ]\n    ];\n\n    \/\/ ========== OUTPUT ==========\n    echo '<script type=\"application\/ld+json\">' . \"\\n\";\n    echo wp_json_encode($schema_webpage, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);\n    echo \"\\n\" . '<\/script>' . \"\\n\";\n}\nadd_action('wp_head', 'add_webpage_schema');\n\n\/\/ ========== FUNGSI BANTUAN ==========\nif (!function_exists('get_optimized_meta_description')) {\n    function get_optimized_meta_description() {\n        global $post;\n        \n        if ((is_single() || is_page()) && $post) {\n            $excerpt = get_the_excerpt($post);\n            if (!empty($excerpt)) {\n                return wp_trim_words($excerpt, 55, '...');\n            }\n            \n            $content = get_post_field('post_content', $post->ID);\n            $content = wp_strip_all_tags($content);\n            return wp_trim_words($content, 55, '...');\n        }\n        \n        return get_bloginfo('description');\n    }\n}\n\n\/\/ END WebPage Schema\n<\/pre>","protected":false},"excerpt":{"rendered":"KEYWORD DI SCHEMA WEBPAGE DENGAN FIELD KEYWORD BLOG DWIYANTI.COM &#8212;- \/\/ SCHEMA WEBPAGE \/\/ METABOX DI ADMIN function add_schema_keywords_metabox_webpage() { add_meta_box( &#8216;schema_keywords_metabox_webpage&#8217;, &#8216;Schema Keywords Manual&#8217;, &#8216;render_schema_keywords_metabox_webpage&#8217;, &#8216;page&#8217;, \/\/ Untuk halaman (page) &#8216;normal&#8217;, &#8216;default&#8217; ); } add_action(&#8216;add_meta_boxes&#8217;, &#8216;add_schema_keywords_metabox_webpage&#8217;); function render_schema_keywords_metabox_webpage($post) { wp_nonce_field(&#8216;schema_keywords_nonce&#8217;, &#8216;schema_keywords_nonce_field&#8217;); $schema_keywords = get_post_meta($post->ID, &#8216;_schema_keywords_manual&#8217;, true); ?> Masukkan Keywords untuk Schema WebPage (pisahkan dengan [&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-383","post","type-post","status-publish","format-standard","hentry","category-schema"],"_links":{"self":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/383","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=383"}],"version-history":[{"count":1,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/383\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/posts\/383\/revisions\/384"}],"wp:attachment":[{"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/media?parent=383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/categories?post=383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tools.dwiyanti.com\/blog\/wp-json\/wp\/v2\/tags?post=383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}