Manual Article Schema Markup

Here’s a code snippet for article schema markup with dynamic content from a WordPress site:

<?php
// Get the post ID, title, and permalink
$post_id = get_the_ID();
$post_title = get_the_title();
$post_permalink = get_permalink();
?>

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Article",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "<?php echo $post_permalink; ?>"
  },
  "headline": "<?php echo $post_title; ?>",
  "image": {
    "@type": "ImageObject",
    "url": "<?php echo get_the_post_thumbnail_url($post_id, 'full'); ?>",
    "height": "800",
    "width": "800"
  },
  "datePublished": "<?php echo get_the_date('c'); ?>",
  "dateModified": "<?php echo get_the_modified_date('c'); ?>",
  "author": {
    "@type": "Person",
    "name": "<?php the_author_meta('display_name'); ?>"
  },
   "publisher": {
    "@type": "Organization",
    "name": "<?php bloginfo('name'); ?>",
    "logo": {
      "@type": "ImageObject",
      "url": "<?php echo get_template_directory_uri(); ?>/images/logo.png",
      "width": 600,
      "height": 60
    }
  },
  "description": "<?php echo get_the_excerpt(); ?>"
}
</script>

In this example, we’re using PHP to dynamically populate the article schema markup with the post title, permalink, featured image, publication date, modification date, author name, site name, and site logo. You can customize the image dimensions, author information, and site logo as needed. Make sure to place this code snippet in the header of your WordPress site and inside the loop, so that it is included on all individual post pages.

Leave comment or code correction