ID); $type = !empty($meta['jsonld_type']) ? $meta['jsonld_type'] : 'Article'; // Default type $data = [ '@context' => 'https://schema.org', '@type' => $type, 'mainEntityOfPage' => [ '@type' => 'WebPage', '@id' => get_permalink($post), ], 'headline' => Helpers::get_seo_title($post), 'description' => Helpers::get_seo_description($post), 'url' => get_permalink($post), 'datePublished' => get_the_date('c', $post), 'dateModified' => get_the_modified_date('c', $post), ]; // Content (Article/BlogPosting only) if (in_array($type, ['Article', 'BlogPosting'])) { $content = strip_shortcodes($post->post_content); $content = wp_strip_all_tags($content); $data['articleBody'] = $content; $data['wordCount'] = str_word_count($content); } // Author $author_id = $post->post_author; $author_schema = [ '@type' => 'Person', 'name' => get_the_author_meta('display_name', $author_id), 'url' => get_author_posts_url($author_id), ]; // Author Job Title $job_title = get_the_author_meta('at_seo_job_title', $author_id); if ($job_title) { $author_schema['jobTitle'] = $job_title; } // Author SameAs $same_as = get_the_author_meta('at_seo_same_as', $author_id); if ($same_as) { $urls = array_filter(array_map('trim', explode("\n", $same_as))); if (!empty($urls)) { $author_schema['sameAs'] = array_values($urls); } } $data['author'] = $author_schema; // Publisher (Inferred from Site Info) $data['publisher'] = [ '@type' => 'Organization', 'name' => get_bloginfo('name'), 'logo' => [ '@type' => 'ImageObject', 'url' => get_site_icon_url() ?: home_url('/favicon.ico'), // Fallback ] ]; // Image $thumb = get_the_post_thumbnail_url($post, 'full'); if ($thumb) { $data['image'] = [ '@type' => 'ImageObject', 'url' => $thumb, ]; } return $data; } public static function generate_breadcrumb($post) { $items = []; $position = 1; // 1. Home $items[] = [ '@type' => 'ListItem', 'position' => $position++, 'name' => 'Home', 'item' => home_url('/') ]; // 2. Blog Page (for Posts) if (get_post_type($post) === 'post') { $posts_page_id = get_option('page_for_posts'); if ($posts_page_id) { $items[] = [ '@type' => 'ListItem', 'position' => $position++, 'name' => get_the_title($posts_page_id), 'item' => get_permalink($posts_page_id) ]; } } // 3. Category (for Posts) if (get_post_type($post) === 'post') { $categories = get_the_category($post->ID); if (!empty($categories)) { $category = $categories[0]; // Primary (first) $items[] = [ '@type' => 'ListItem', 'position' => $position++, 'name' => $category->name, 'item' => get_category_link($category->term_id) ]; } } // 4. Current Page (Leaf) $items[] = [ '@type' => 'ListItem', 'position' => $position++, 'name' => get_the_title($post), // item is optional for the last item, but good for ID 'item' => get_permalink($post) ]; return [ '@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => $items ]; } }