Advertisement
grage95

Schema NewsArtikel

Nov 25th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.81 KB | None | 0 0
  1. <?php
  2. function generateSchemaMarkup($title, $description, $authorName, $publishDate, $modifiedDate, $url, $publisherName, $publisherLogo, $imageUrl) {
  3.     $schema = [
  4.         "@context" => "https://schema.org",
  5.         "@type" => "NewsArticle",
  6.         "headline" => $title,
  7.         "description" => $description,
  8.         "author" => [
  9.             "@type" => "Person",
  10.             "name" => $authorName
  11.         ],
  12.         "datePublished" => $publishDate,
  13.         "dateModified" => $modifiedDate,
  14.         "mainEntityOfPage" => [
  15.             "@type" => "WebPage",
  16.             "@id" => $url
  17.         ],
  18.         "publisher" => [
  19.             "@type" => "Organization",
  20.             "name" => $publisherName,
  21.             "logo" => [
  22.                 "@type" => "ImageObject",
  23.                 "url" => $publisherLogo
  24.             ]
  25.         ],
  26.         "image" => $imageUrl
  27.     ];
  28.  
  29.     return json_encode($schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
  30. }
  31.  
  32. // Contoh penggunaan
  33. $title = "Teknologi AI dalam Pendidikan";
  34. $description = "Artikel yang membahas perkembangan teknologi AI dalam pendidikan, manfaatnya, tantangan yang dihadapi, dan implementasi di dunia nyata.";
  35. $authorName = "Nama Penulis";
  36. $publishDate = "2024-11-26";
  37. $modifiedDate = "2024-11-26";
  38. $url = "https://contoh.com/artikel/teknologi-ai-pendidikan";
  39. $publisherName = "Nama Situs";
  40. $publisherLogo = "https://contoh.com/logo.png";
  41. $imageUrl = "https://contoh.com/images/teknologi-ai-pendidikan.jpg";
  42.  
  43. echo generateSchemaMarkup($title, $description, $authorName, $publishDate, $modifiedDate, $url, $publisherName, $publisherLogo, $imageUrl);
  44. ?>
  45. <script type="application/ld+json">
  46. <?php echo generateSchemaMarkup($title, $description, $authorName, $publishDate, $modifiedDate, $url, $publisherName, $publisherLogo, $imageUrl); ?>
  47. </script>
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement