diff --git a/includes/class-newspack-blocks-api.php b/includes/class-newspack-blocks-api.php index df7f77f36..c52301020 100644 --- a/includes/class-newspack-blocks-api.php +++ b/includes/class-newspack-blocks-api.php @@ -159,7 +159,9 @@ public static function newspack_blocks_get_primary_category( $object ) { return ''; } - return $category->name; + $linked_category = '' . $category->name . ''; + + return apply_filters( 'newspack_blocks_categories', $linked_category ); } /** diff --git a/src/blocks/carousel/edit.js b/src/blocks/carousel/edit.js index e69d0b91c..60dd904ec 100644 --- a/src/blocks/carousel/edit.js +++ b/src/blocks/carousel/edit.js @@ -13,7 +13,7 @@ import { __ } from '@wordpress/i18n'; import { InspectorControls } from '@wordpress/block-editor'; // eslint-disable-next-line @wordpress/no-unsafe-wp-apis import { dateI18n, __experimentalGetSettings } from '@wordpress/date'; -import { Component, createRef, Fragment } from '@wordpress/element'; +import { Component, createRef, Fragment, RawHTML } from '@wordpress/element'; import { BaseControl, Button, @@ -303,7 +303,7 @@ class Edit extends Component { { showCategory && ( ! post.newspack_post_sponsors || post.newspack_sponsors_show_categories ) && ( - { decodeEntities( post.newspack_category_info ) } + { decodeEntities( post.newspack_category_info ) } ) } ) } diff --git a/src/blocks/carousel/view.php b/src/blocks/carousel/view.php index 1c48ac005..ab90772f2 100644 --- a/src/blocks/carousel/view.php +++ b/src/blocks/carousel/view.php @@ -111,36 +111,10 @@ function newspack_blocks_render_block_carousel( $attributes ) { get_primary_term(); - if ( $category_id ) { - $category = get_term( $category_id ); - } - } - - if ( ! $category ) { - $categories_list = get_the_category(); - if ( ! empty( $categories_list ) ) { - $category = $categories_list[0]; - } - } - - if ( $attributes['showCategory'] && $category && ( empty( $sponsors ) || Newspack_Blocks::newspack_display_sponsors_and_categories( $sponsors ) ) ) : - ?> - term_id ); ?> - - - - name ); ?> - - - { decodeEntities( post.newspack_category_info ) } + { decodeEntities( post.newspack_category_info ) } ) } ) } diff --git a/src/blocks/homepage-articles/templates/article.php b/src/blocks/homepage-articles/templates/article.php index 547a4d026..f11439096 100644 --- a/src/blocks/homepage-articles/templates/article.php +++ b/src/blocks/homepage-articles/templates/article.php @@ -56,21 +56,6 @@ function( $data ) { if ( $attributes['fetchPriority'] && in_array( $attributes['fetchPriority'], [ 'high', 'low', 'auto' ], true ) ) { $thumbnail_args['fetchpriority'] = $attributes['fetchPriority']; } - $category = false; - // Use Yoast primary category if set. - if ( class_exists( 'WPSEO_Primary_Term' ) ) { - $primary_term = new WPSEO_Primary_Term( 'category', $post_id ); - $category_id = $primary_term->get_primary_term(); - if ( $category_id ) { - $category = get_term( $category_id ); - } - } - if ( ! $category ) { - $categories_list = get_the_category(); - if ( ! empty( $categories_list ) ) { - $category = $categories_list[0]; - } - } // Support Newspack Listings hide author/publish date options. $hide_author = apply_filters( 'newspack_listings_hide_author', false ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound @@ -105,19 +90,20 @@ class=""
- - term_id ); ?> + + get_primary_term(); + if ( $category_id ) { + $category = get_term( $category_id ); + } + } + if ( ! $category ) { + $categories_list = get_the_category(); + if ( ! empty( $categories_list ) ) { + $category = $categories_list[0]; + } + } + + $category_link = get_category_link( $category->term_id ); + $category_formatted = esc_html( $category->name ); + + if ( ! empty( $category_link ) ) { + $category_formatted = '' . esc_html( $category->name ) . ''; + } + + if ( $category ) { + return apply_filters( 'newspack_blocks_categories', $category_formatted ); + } +} + /** * Inject amp-state containing all post IDs visible on page load. */