Skip to content

Instantly share code, notes, and snippets.

@barking-horse
Last active March 19, 2021 11:40
Show Gist options
  • Save barking-horse/2bc3f36a1e13761851a0a15b9a00e4bf to your computer and use it in GitHub Desktop.
Save barking-horse/2bc3f36a1e13761851a0a15b9a00e4bf to your computer and use it in GitHub Desktop.
Add Schema.org Markup to WordPress post for a Better SEO
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>" itemscope itemtype="https://schema.org/Article">
<header>
<?php the_title( '<h1 class="title entry-title" itemprop="headline">', '</h1>' ); ?>
<?php echo get_the_post_thumbnail( $post->ID, 'hero', array('class' => 'img-fluid mx-auto', 'itemprop' => 'image') ); ?>
<div class="entry-meta">
<time pubdate itemprop="datePublished" datetime="<?php the_time( 'c' ); ?>" content="<?php the_time( 'c' ); ?>">
<?php the_time( get_option( 'date_format' ) ); ?>
</time>
<div>Catégories: <span itemprop="about"><?php the_category(', '); ?></span></div>
<div>Tags: <span itemprop="keywords"><?php the_tags(''); ?></span></div>
<div itemprop="author" itemscope itemtype="https://schema.org/Person">
<span itemprop="name"><?php the_author();?></span>
</div>
</div>
</header>
<div class="entry-content">
<div itemprop="articleBody">
<?php the_content(); ?>
</div>
<div class="entry-footer">
<?php
wp_link_pages(
array(
'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
'after' => '</div>',
)
);
?>
</div>
</div>
</article>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment