diff --git a/author.php b/author.php index 4314092390..e7d9943998 100755 --- a/author.php +++ b/author.php @@ -43,6 +43,7 @@ 'width' => '300', 'height' => '300', ]; + $context['og_type'] = 'profile'; $author_share_buttons = new stdClass(); $author_share_buttons->title = $author->name; diff --git a/category.php b/category.php index 7cf84fc3e9..0b72492ad9 100644 --- a/category.php +++ b/category.php @@ -16,9 +16,12 @@ $templates = [ 'taxonomy.twig', 'index.twig' ]; $context = Timber::get_context(); -$context['taxonomy'] = get_queried_object(); -$context['wp_title'] = $context['taxonomy']->name; +$taxonomy = get_queried_object(); +$context['taxonomy'] = $taxonomy; +$context['wp_title'] = $taxonomy->name; $context['canonical_link'] = home_url($wp->request); +$context['og_type'] = 'website'; +$context['og_description'] = $taxonomy->description; if (!empty(planet4_get_option('new_ia'))) { $view = ListingPageGridView::is_active() ? 'grid' : 'list'; @@ -34,7 +37,7 @@ } $post_args = [ - 'cat' => $context['taxonomy']->term_id, + 'cat' => $taxonomy->term_id, 'posts_per_page' => 10, 'post_type' => 'post', 'paged' => 1, diff --git a/src/Post.php b/src/Post.php index 1690858845..bb422e68d9 100644 --- a/src/Post.php +++ b/src/Post.php @@ -394,6 +394,7 @@ public function get_og_title(): string public function get_og_description(): string { $og_desc = get_post_meta($this->id, 'p4_og_description', true); + if ('' === $og_desc) { return $this->post_excerpt; } diff --git a/tag.php b/tag.php index 630c42633c..6137d66463 100644 --- a/tag.php +++ b/tag.php @@ -42,13 +42,14 @@ $context = Timber::get_context(); if ($post instanceof \WP_Post) { $post = new Post($post->ID); + Context::set_og_meta_fields($context, $post); } -Context::set_og_meta_fields($context, $post); $context['tag'] = $tag; $context['tag_name'] = single_tag_title('', false); $context['tag_description'] = wpautop($context['tag']->description); $context['canonical_link'] = home_url($wp->request); +$context['og_type'] = 'website'; if (!empty(planet4_get_option('new_ia'))) { // Temporary fix with rewind, cf. https://github.com/WordPress/gutenberg/issues/53593 diff --git a/taxonomy.php b/taxonomy.php index 46d5e4e800..5f72e5bd30 100755 --- a/taxonomy.php +++ b/taxonomy.php @@ -1,7 +1,7 @@ name; +$taxonomy = get_queried_object(); +$context['taxonomy'] = $taxonomy; +$context['wp_title'] = $taxonomy->name; $context['canonical_link'] = home_url($wp->request); +$context['og_type'] = 'website'; +$context['og_description'] = $taxonomy->description; if (!empty(planet4_get_option('new_ia'))) { $context['page_category'] = 'Listing Page'; @@ -51,9 +54,9 @@ 'has_password' => false, // Skip password protected content. 'tax_query' => [ [ - 'taxonomy' => $context['taxonomy']->taxonomy, + 'taxonomy' => $taxonomy->taxonomy, 'field' => 'slug', - 'terms' => $context['taxonomy']->slug, + 'terms' => $taxonomy->slug, ], ], ]; diff --git a/templates/base.twig b/templates/base.twig index 87cc9e72f0..4031038236 100644 --- a/templates/base.twig +++ b/templates/base.twig @@ -1,6 +1,6 @@ {% block html_head_container %} -{% include 'html-header.twig' with { 'canonical_link': canonical_link } %} +{% include 'html-header.twig' %} {% endblock %} diff --git a/templates/blocks/meta_fields.twig b/templates/blocks/meta_fields.twig index 5ab1271c30..a37a9e494a 100644 --- a/templates/blocks/meta_fields.twig +++ b/templates/blocks/meta_fields.twig @@ -1,8 +1,15 @@ -{% if ((post and (1 != fn('post_password_required', post))) or author is defined) or tag_name is defined %} +{% set is_listing_page = tag_name is defined or taxonomy is defined or author is defined %} +{% set is_news_page = page_category == 'News' %} + +{% if (post and (1 != fn('post_password_required', post))) or is_listing_page or is_news_page %} {% if (author.description is defined and author.description) %} {% set meta_description = author.description|striptags %} {% elseif (post.post_excerpt is defined and post.post_excerpt) %} {% set meta_description = post.post_excerpt|striptags %} + {% elseif (tag_description is defined and tag_description) %} + {% set meta_description = tag_description|striptags %} + {% elseif (taxonomy is defined and taxonomy.description) %} + {% set meta_description = taxonomy.description|striptags %} {% else %} {% set meta_description = site.description %} {% endif %} @@ -25,10 +32,16 @@ - + {% if (og_type) %} + + {% else %} + + {% endif %} {% if (og_description) %} + {% elseif (tag_description) %} + {% endif %} {% if (og_image_data) %}