From ff343c854e0e42bc52cea4c2694f95356b42db96 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Fri, 9 Aug 2024 15:12:13 -0400 Subject: [PATCH] SEO: Fix opengraph tags on category and topic pages Fixes #79 --- .../themes/wporg-documentation-2022/functions.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/wp-content/themes/wporg-documentation-2022/functions.php b/source/wp-content/themes/wporg-documentation-2022/functions.php index be8aa82..439b0da 100644 --- a/source/wp-content/themes/wporg-documentation-2022/functions.php +++ b/source/wp-content/themes/wporg-documentation-2022/functions.php @@ -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(); @@ -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;