Skip to content

Commit

Permalink
SEO: Fix opengraph tags on category and topic pages
Browse files Browse the repository at this point in the history
Fixes #79
  • Loading branch information
ryelle committed Aug 9, 2024
1 parent 7f50ff7 commit ff343c8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source/wp-content/themes/wporg-documentation-2022/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ function( $html ) {
'twitter:card' => 'summary_large_image',
'twitter:creator' => '@WordPress',
);
} else if ( is_category() ) {
$tags['og:image'] = 'https://wordpress.org/files/2022/08/embed-image.png';
return $tags;
}

$post = get_post();
Expand All @@ -353,6 +356,14 @@ function( $html ) {
$title = get_the_title();
$desc = get_the_excerpt();

if ( is_page() ) {
$term_slug = ( 'overview' === $post->post_name ) ? 'wordpress-overview' : $post->post_name;
$term = get_term_by( 'slug', $term_slug, 'category' );
if ( $term ) {
$desc = trim( strip_tags( term_description( $term->term_id ) ) );
}
}

$tags['og:title'] = $title;
$tags['twitter:text:title'] = $title;
$tags['og:description'] = $desc;
Expand Down

0 comments on commit ff343c8

Please sign in to comment.