Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function generateSchemaMarkup($title, $description, $authorName, $publishDate, $modifiedDate, $url, $publisherName, $publisherLogo, $imageUrl) {
- $schema = [
- "@context" => "https://schema.org",
- "@type" => "NewsArticle",
- "headline" => $title,
- "description" => $description,
- "author" => [
- "@type" => "Person",
- "name" => $authorName
- ],
- "datePublished" => $publishDate,
- "dateModified" => $modifiedDate,
- "mainEntityOfPage" => [
- "@type" => "WebPage",
- "@id" => $url
- ],
- "publisher" => [
- "@type" => "Organization",
- "name" => $publisherName,
- "logo" => [
- "@type" => "ImageObject",
- "url" => $publisherLogo
- ]
- ],
- "image" => $imageUrl
- ];
- return json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
- }
- // Contoh penggunaan
- $title = "Teknologi AI dalam Pendidikan";
- $description = "Artikel yang membahas perkembangan teknologi AI dalam pendidikan, manfaatnya, tantangan yang dihadapi, dan implementasi di dunia nyata.";
- $authorName = "Nama Penulis";
- $publishDate = "2024-11-26";
- $modifiedDate = "2024-11-26";
- $url = "https://contoh.com/artikel/teknologi-ai-pendidikan";
- $publisherName = "Nama Situs";
- $publisherLogo = "https://contoh.com/logo.png";
- $imageUrl = "https://contoh.com/images/teknologi-ai-pendidikan.jpg";
- echo generateSchemaMarkup($title, $description, $authorName, $publishDate, $modifiedDate, $url, $publisherName, $publisherLogo, $imageUrl);
- ?>
- <script type="application/ld+json">
- <?php echo generateSchemaMarkup($title, $description, $authorName, $publishDate, $modifiedDate, $url, $publisherName, $publisherLogo, $imageUrl); ?>
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement