'https://schema.org', '@type' => 'Organization', '@id' => trailingslashit($org_url) . '#organization', 'name' => $org_name, 'url' => $org_url, ]; if ($org_logo) { $org_schema['logo'] = [ '@type' => 'ImageObject', 'url' => $org_logo ]; } if (!empty($social_urls)) { // Should clean/validate URLs? Assuming array of strings. // Options::get returns array if default is array, but let's ensure. if (is_string($social_urls)) { $social_urls = array_map('trim', explode("\n", $social_urls)); } $org_schema['sameAs'] = array_values(array_filter($social_urls)); } $schemas[] = $org_schema; } // WebSite // PRD 1.2 Required fields: name, url, publisher -> Organization @id // Must output exactly once (which this function does) // Use stable @id values // We need site name and url $site_name = get_bloginfo('name'); $site_url = get_site_url(); // Or home_url(), PRD 1.2 "url". if ($site_name && $site_url) { $website_schema = [ '@context' => 'https://schema.org', '@type' => 'WebSite', '@id' => trailingslashit($site_url) . '#website', 'name' => $site_name, 'url' => $site_url, ]; if ($org_name && $org_url) { $website_schema['publisher'] = [ '@id' => trailingslashit($org_url) . '#organization' ]; } // Optional: SearchAction // PRD 1.2 "Optional schemas: SearchAction". // Implementation: Simple potential search action if search is enabled? // "Public" search action. $website_schema['potentialAction'] = [ '@type' => 'SearchAction', 'target' => [ '@type' => 'EntryPoint', 'urlTemplate' => trailingslashit($site_url) . '?s={search_term_string}' ], 'query-input' => 'required name=search_term_string' ]; $schemas[] = $website_schema; } if (!empty($schemas)) { echo "\n\n"; foreach ($schemas as $schema) { echo '\n"; } } } }