From 6287b218f3531ff6a813deb44d8478d4eed161b5 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 6 Jan 2026 18:42:50 -0700 Subject: [PATCH 01/20] feat: add theme support for tags as labels --- newspack-theme/functions.php | 38 +++++- newspack-theme/inc/newspack-tag-labels.php | 121 ++++++++++++++++++ .../sass/plugins/newspack-tag-labels.scss | 70 ++++++++++ .../content/content-archive.php | 9 +- .../content/content-excerpt.php | 9 +- .../template-parts/header/entry-header.php | 9 +- scripts/compile-scss.js | 4 + 7 files changed, 250 insertions(+), 10 deletions(-) create mode 100644 newspack-theme/inc/newspack-tag-labels.php create mode 100644 newspack-theme/sass/plugins/newspack-tag-labels.scss diff --git a/newspack-theme/functions.php b/newspack-theme/functions.php index 79473f0f8..f6efbeaa8 100755 --- a/newspack-theme/functions.php +++ b/newspack-theme/functions.php @@ -179,6 +179,7 @@ function newspack_setup() { $secondary_color_variation = newspack_adjust_brightness( $secondary_color, -40 ); // Editor color palette. + // phpcs:disable Squiz.Commenting.InlineComment.InvalidEndChar -- Let's not be too precious about the brief comments here. add_theme_support( 'editor-color-palette', array( @@ -224,6 +225,7 @@ function newspack_setup() { ), ) ); + // phpcs:enable Squiz.Commenting.InlineComment.InvalidEndChar add_theme_support( 'editor-gradient-presets', @@ -267,7 +269,7 @@ function newspack_setup() { // Add support for responsive embedded content. add_theme_support( 'responsive-embeds' ); - // Make our theme AMP/PWA Native + // Make our theme AMP/PWA Native. add_theme_support( 'amp', array( @@ -278,7 +280,7 @@ function newspack_setup() { ) ); - // Add custom theme support - post subtitle + // Add custom theme support - post subtitle. add_theme_support( 'post-subtitle' ); } endif; @@ -411,7 +413,7 @@ function newspack_widgets_init() { function newspack_content_width() { $content_width = 780; - // Check if front page or using One-Column Wide template + // Check if front page or using One-Column Wide template. if ( ( is_front_page() && 'posts' !== get_option( 'show_on_front' ) ) || is_page_template( 'single-wide.php' ) ) { $content_width = 1200; } @@ -585,6 +587,7 @@ function newspack_enqueue_scripts() { } // Featured Image options. + // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter -- TODO: Should we set $in_footer? wp_register_script( 'newspack-extend-featured-image-script', get_theme_file_uri( '/js/dist/extend-featured-image-editor.js' ), @@ -814,6 +817,8 @@ function newspack_check_current_template() { * * The 'admin-color-' prefix is used to make sure the classes get moved to the tag in the iframed editor as a work-around. * See https://github.com/WordPress/gutenberg/issues/28538 for more details. + * + * @param string $classes Existing classes. */ function newspack_filter_admin_body_class( $classes ) { if ( ! function_exists( 'get_current_screen' ) ) { @@ -853,6 +858,8 @@ function newspack_filter_admin_body_class( $classes ) { /** * Enqueue CSS styles for the editor that use the tag. + * + * @param string $classes Existing classes. */ function newspack_enqueue_editor_override_assets() { // In the iframe editor, canvas styles are loaded via block assets. @@ -974,6 +981,9 @@ function newspack_register_meta() { /** * Migrate theme settings when switching within the family of Newspack themes. * + * @param string $old_name The name of the old theme. + * @param WP_Theme|false $old_theme The old theme object (default: false). + * * @since Newspack Theme 1.0.0 */ function newspack_migrate_settings( $old_name, $old_theme = false ) { @@ -1123,6 +1133,10 @@ function newspack_sanitize_svgs() { /** * Truncates text to a specific character length, without breaking a character. + * + * @param string $content The text to truncate. + * @param int $length The character length to truncate to. + * @param string $after Text to append after truncation. Default is '...'. */ function newspack_truncate_text( $content, $length, $after = '...' ) { // If content is already shorter than the truncate length, return it. @@ -1130,10 +1144,10 @@ function newspack_truncate_text( $content, $length, $after = '...' ) { return $content; } - // Find the first space after the desired length: + // Find the first space after the desired length. $breakpoint = strpos( $content, ' ', $length ); - // Make sure $breakpoint isn't returning false, and is less than length of content: + // Make sure $breakpoint isn't returning false, and is less than length of content. if ( false !== $breakpoint && $breakpoint < strlen( $content ) - 1 ) { $content = substr( $content, 0, $breakpoint ) . $after; } @@ -1184,6 +1198,8 @@ function newspack_get_post_toggle_post_types() { /** * Co-authors in RSS and other feeds * /wp-includes/feed-rss2.php uses the_author(), so we selectively filter the_author value + * + * @param string $the_author The author's display name. */ function newspack_coauthors_in_rss( $the_author ) { if ( ! is_feed() || ! function_exists( 'coauthors' ) ) { @@ -1213,9 +1229,11 @@ function newspack_theme_newspack_ads_maybe_use_responsive_placement( $responsive /** * Add a extra span and class to the_archive_title, for easier styling. + * + * @param string $title Archive title to be displayed. */ function newspack_update_the_archive_title( $title ) { - // Split the title into parts so we can wrap them with spans: + // Split the title into parts so we can wrap them with spans. $title_parts = explode( '', $title, 2 ); $title_format = get_theme_mod( 'archive_title_format', 'default' ); @@ -1347,6 +1365,13 @@ function newspack_dequeue_mediaelement() { require get_template_directory() . '/inc/newspack-sponsors.php'; } +/** + * Load Tag Labels compatibility file. + */ +if ( class_exists( '\Newspack\Tag_Labels' ) ) { + require get_template_directory() . '/inc/newspack-tag-labels.php'; +} + /** * Load Newsletters compatibility file. */ @@ -1377,4 +1402,3 @@ function newspack_dequeue_mediaelement() { * Woo Templates cache handling */ require get_template_directory() . '/woocommerce/templates.php'; - diff --git a/newspack-theme/inc/newspack-tag-labels.php b/newspack-theme/inc/newspack-tag-labels.php new file mode 100644 index 000000000..dd404c05f --- /dev/null +++ b/newspack-theme/inc/newspack-tag-labels.php @@ -0,0 +1,121 @@ +'; + foreach ( $labels as $label ) { + if ( $links && $label['link'] ) { + $labels_html .= ''; + } else { + $labels_html .= '' . esc_html( $label['flag'] ) . ''; + } + } + $labels_html .= ''; + + return $labels_html; + } +endif; + +if ( ! function_exists( 'newspack_display_tag_labels' ) ) : + /** + * Outputs HTML for given tag labels. + * + * @param array $labels Labels to display. + * @param bool $links Whether to include links to tag archives. + * + * @return null + */ + function newspack_display_tag_labels( $labels = null, $links = true ) { + if ( empty( $labels ) ) { + return null; + } + + echo wp_kses_post( newspack_generate_tag_labels( $labels, $links, array( 'tag-labels', 'cat-links' ) ) . ' ' ); + + return null; + } +endif; + +/** + * Enqueue scripts. + * + * - Adds label to post title where applicable. + * + * @param string $post_title Title of the post. + * @param int $post_id ID of the post. + * + * @return null + */ +function newspack_tag_labels_for_post_title( $post_title, $post_id ) { + + // Apply title changes only to front/home views and non-singular views. + if ( ! class_exists( 'Newspack\Tag_Labels' ) || ( defined( 'WP_CLI' ) && WP_CLI ) || is_admin() || ( is_singular() && ! ( is_front_page() || is_home() ) ) ) { + return $post_title; + } + + $labels = newspack_get_tag_labels( $post_id ); + if ( empty( $labels ) ) { + return $post_title; + } + + // Disable label links, as entire post title will be linked. + $labels_html = newspack_generate_tag_labels( $labels, false ); + + return $labels_html ? ( $labels_html . ' ' . $post_title ) : $post_title; +} +add_filter( 'the_title', 'newspack_tag_labels_for_post_title', 10, 2 ); + +/** + * Enqueue styles. + */ +function newspack_tag_labels_enqueue_styles() { + if ( ( defined( 'WP_CLI' ) && WP_CLI ) || is_admin() || ! class_exists( 'Newspack\Tag_Labels' ) ) { + return; + } + wp_enqueue_style( + 'newspack-tag-labels-style', + get_template_directory_uri() . '/styles/newspack-tag-labels.css', + array( 'newspack-style' ), + wp_get_theme()->get( 'Version' ) + ); +} +add_action( 'wp_enqueue_scripts', 'newspack_tag_labels_enqueue_styles' ); diff --git a/newspack-theme/sass/plugins/newspack-tag-labels.scss b/newspack-theme/sass/plugins/newspack-tag-labels.scss new file mode 100644 index 000000000..b4155ab39 --- /dev/null +++ b/newspack-theme/sass/plugins/newspack-tag-labels.scss @@ -0,0 +1,70 @@ +@use "../variables-site/variables-site"; +@use "../mixins/mixins-main"; +@use "../mixins/utilities"; +@use "../variables-site/structure"; + +// Tag labels +.tag-labels { + align-items: stretch; + display: inline-flex; + /* margin-right: 0.5rem; */ + position: relative; + + a, + a:visited { + color: #fff; + } + + a:hover { + opacity: 0.8; + } +} + +/* stylelint-disable selector-type-no-unknown */ +.tag-labels, +amp-script .tag-labels { + .tag-label { + background: var(--newspack-theme-color-highlight); + color: var(--newspack-theme-color-text-main); + line-height: 1; + padding: 0.3em 0.5em; + text-transform: uppercase; + } +} +/* stylelint-enable */ + +/* Single Posts */ +.single { + // When categories are visible + .tag-labels { + display: inline-flex; + } + + .tag-labels + .cat-links { + display: inline-block; + } +} + +// Archives +.search, +.archive, +.blog { + article { + .tag-labels { + display: inline-flex; + font-size: 65%; + } + } +} + +.search article .tag-labels + .cat-links { + display: inline-block; +} + +.tag-labels + .page-title { + &::before, + &::after, + .page-subtitle { + display: none; + } +} diff --git a/newspack-theme/template-parts/content/content-archive.php b/newspack-theme/template-parts/content/content-archive.php index 804bea328..ff206cb72 100644 --- a/newspack-theme/template-parts/content/content-archive.php +++ b/newspack-theme/template-parts/content/content-archive.php @@ -14,6 +14,11 @@ $display_sponsors_and_categories = newspack_display_sponsors_and_categories( $native_sponsors ); $display_sponsors_and_authors = newspack_display_sponsors_and_authors( $native_sponsors ); } + +// Get tag labels for this post. +if ( function_exists( 'newspack_get_tag_labels' ) ) { + $tag_labels = newspack_get_tag_labels( get_the_id() ); +} ?>
> @@ -26,9 +31,11 @@ // Get label for native post sponsors. newspack_sponsor_label( $native_sponsors ); if ( $display_sponsors_and_categories ) { + newspack_display_tag_labels( $tag_labels ); newspack_categories(); } } else { + newspack_display_tag_labels( $tag_labels ); newspack_categories(); } } @@ -37,7 +44,7 @@ ', esc_url( get_permalink() ) ), '' ); ?>
- +
diff --git a/newspack-theme/template-parts/content/content-excerpt.php b/newspack-theme/template-parts/content/content-excerpt.php index ca9c8ffd1..f38b85795 100755 --- a/newspack-theme/template-parts/content/content-excerpt.php +++ b/newspack-theme/template-parts/content/content-excerpt.php @@ -14,6 +14,11 @@ $display_sponsors_and_categories = newspack_display_sponsors_and_categories( $native_sponsors ); $display_sponsors_and_authors = newspack_display_sponsors_and_authors( $native_sponsors ); } + +// Get tag labels for this post. +if ( function_exists( 'newspack_get_tag_labels' ) ) { + $tag_labels = newspack_get_tag_labels( get_the_id() ); +} ?>
> @@ -26,9 +31,11 @@ // Get label for native post sponsors. newspack_sponsor_label( $native_sponsors ); if ( $display_sponsors_and_categories ) { + newspack_display_tag_labels( $tag_labels ); newspack_categories(); } } else { + newspack_display_tag_labels( $tag_labels ); newspack_categories(); } } @@ -37,7 +44,7 @@ ', esc_url( get_permalink() ) ), '' ); ?>
- +
diff --git a/newspack-theme/template-parts/header/entry-header.php b/newspack-theme/template-parts/header/entry-header.php index 989fda08e..119701e94 100755 --- a/newspack-theme/template-parts/header/entry-header.php +++ b/newspack-theme/template-parts/header/entry-header.php @@ -13,6 +13,11 @@ $display_sponsors_and_authors = newspack_display_sponsors_and_authors( $native_sponsors ); } +// Get tag labels for this post. +if ( function_exists( 'newspack_get_tag_labels' ) ) { + $tag_labels = newspack_get_tag_labels( get_the_id() ); +} + // Get page title visibility. $page_hide_title = get_post_meta( $post->ID, 'newspack_hide_page_title', true ); @@ -30,9 +35,11 @@ if ( ! empty( $native_sponsors ) ) { newspack_sponsor_label( $native_sponsors, null, true ); if ( $display_sponsors_and_categories ) { + newspack_display_tag_labels( $tag_labels ); newspack_categories(); } } else { + newspack_display_tag_labels( $tag_labels ); newspack_categories(); } endif; @@ -44,7 +51,7 @@
- +
diff --git a/scripts/compile-scss.js b/scripts/compile-scss.js index 50b087c53..e2771f187 100644 --- a/scripts/compile-scss.js +++ b/scripts/compile-scss.js @@ -132,6 +132,10 @@ const SASS_STYLESHEETS = [ outFile: 'newspack-theme/styles/newspack-sponsors-editor.css', withRTL: true, }, + { + inFile: 'newspack-theme/sass/plugins/newspack-tag-labels.scss', + outFile: 'newspack-theme/styles/newspack-tag-labels.css', + }, { inFile: 'newspack-theme/tribe-events/tribe-events.scss', outFile: 'newspack-theme/tribe-events/tribe-events.css', From c9835a23b8d4660f712654bb575327873b6a14fb Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 6 Jan 2026 19:13:03 -0700 Subject: [PATCH 02/20] fix: continuity checks for tag labels support --- newspack-theme/template-parts/content/content-archive.php | 8 ++++++-- newspack-theme/template-parts/content/content-excerpt.php | 8 ++++++-- newspack-theme/template-parts/header/entry-header.php | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/newspack-theme/template-parts/content/content-archive.php b/newspack-theme/template-parts/content/content-archive.php index ff206cb72..4a168eca0 100644 --- a/newspack-theme/template-parts/content/content-archive.php +++ b/newspack-theme/template-parts/content/content-archive.php @@ -31,11 +31,15 @@ // Get label for native post sponsors. newspack_sponsor_label( $native_sponsors ); if ( $display_sponsors_and_categories ) { - newspack_display_tag_labels( $tag_labels ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } newspack_categories(); } } else { - newspack_display_tag_labels( $tag_labels ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } newspack_categories(); } } diff --git a/newspack-theme/template-parts/content/content-excerpt.php b/newspack-theme/template-parts/content/content-excerpt.php index f38b85795..4e57403f0 100755 --- a/newspack-theme/template-parts/content/content-excerpt.php +++ b/newspack-theme/template-parts/content/content-excerpt.php @@ -31,11 +31,15 @@ // Get label for native post sponsors. newspack_sponsor_label( $native_sponsors ); if ( $display_sponsors_and_categories ) { - newspack_display_tag_labels( $tag_labels ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } newspack_categories(); } } else { - newspack_display_tag_labels( $tag_labels ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } newspack_categories(); } } diff --git a/newspack-theme/template-parts/header/entry-header.php b/newspack-theme/template-parts/header/entry-header.php index 119701e94..bd78e633b 100755 --- a/newspack-theme/template-parts/header/entry-header.php +++ b/newspack-theme/template-parts/header/entry-header.php @@ -35,11 +35,15 @@ if ( ! empty( $native_sponsors ) ) { newspack_sponsor_label( $native_sponsors, null, true ); if ( $display_sponsors_and_categories ) { - newspack_display_tag_labels( $tag_labels ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } newspack_categories(); } } else { - newspack_display_tag_labels( $tag_labels ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } newspack_categories(); } endif; From 3c78f8b5fcadf963d7350cac4bf5f9d813e2baac Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 7 Jan 2026 13:49:21 -0700 Subject: [PATCH 03/20] fix: separate consecutive labels --- newspack-theme/sass/plugins/newspack-tag-labels.scss | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/newspack-theme/sass/plugins/newspack-tag-labels.scss b/newspack-theme/sass/plugins/newspack-tag-labels.scss index b4155ab39..602385dba 100644 --- a/newspack-theme/sass/plugins/newspack-tag-labels.scss +++ b/newspack-theme/sass/plugins/newspack-tag-labels.scss @@ -30,6 +30,9 @@ amp-script .tag-labels { padding: 0.3em 0.5em; text-transform: uppercase; } + .tag-label + .tag-label { + margin-left: 0.3em; // Don't collapse multiple labels. + } } /* stylelint-enable */ @@ -39,9 +42,14 @@ amp-script .tag-labels { .tag-labels { display: inline-flex; } - .tag-labels + .cat-links { display: inline-block; + margin-left: 0.5em; + } + + // Workaround margin override for featured images. + .featured-image-behind .cat-links.tag-labels a { + margin-right: 0.5em; } } From 1dfc474227825a9fc8ece8f6461ea9ce6dc695d6 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 8 Jan 2026 14:38:54 -0700 Subject: [PATCH 04/20] fix: apply suggestions from Copilot code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- newspack-theme/inc/newspack-tag-labels.php | 4 ++-- newspack-theme/sass/plugins/newspack-tag-labels.scss | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/newspack-theme/inc/newspack-tag-labels.php b/newspack-theme/inc/newspack-tag-labels.php index dd404c05f..5c3bd2ff6 100644 --- a/newspack-theme/inc/newspack-tag-labels.php +++ b/newspack-theme/inc/newspack-tag-labels.php @@ -9,7 +9,7 @@ /** * Returns array of tag labels for the given post. * - * @param WP_Post $post Post to check. + * @param int|WP_Post|null $post Post to check. * * @return array|null */ @@ -46,7 +46,7 @@ function newspack_generate_tag_labels( $labels = null, $links = true, $outer_cla if ( $links && $label['link'] ) { $labels_html .= ''; } else { - $labels_html .= '' . esc_html( $label['flag'] ) . ''; + $labels_html .= '' . esc_html( $label['flag'] ) . ''; } } $labels_html .= ''; diff --git a/newspack-theme/sass/plugins/newspack-tag-labels.scss b/newspack-theme/sass/plugins/newspack-tag-labels.scss index 602385dba..39089bbbe 100644 --- a/newspack-theme/sass/plugins/newspack-tag-labels.scss +++ b/newspack-theme/sass/plugins/newspack-tag-labels.scss @@ -7,13 +7,12 @@ .tag-labels { align-items: stretch; display: inline-flex; - /* margin-right: 0.5rem; */ position: relative; a, a:visited { color: #fff; - } + } a:hover { opacity: 0.8; From 54fcccbd17ffb6b81419195b47a1f3bed58c9b1c Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 8 Jan 2026 15:02:05 -0700 Subject: [PATCH 05/20] fix: tweaks; Copilot suggestions --- newspack-theme/inc/newspack-tag-labels.php | 10 ++++------ .../template-parts/content/content-archive.php | 2 +- .../template-parts/content/content-excerpt.php | 2 +- newspack-theme/template-parts/header/entry-header.php | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/newspack-theme/inc/newspack-tag-labels.php b/newspack-theme/inc/newspack-tag-labels.php index 5c3bd2ff6..e37fa70aa 100644 --- a/newspack-theme/inc/newspack-tag-labels.php +++ b/newspack-theme/inc/newspack-tag-labels.php @@ -43,9 +43,9 @@ function newspack_generate_tag_labels( $labels = null, $links = true, $outer_cla $labels_html = ''; $labels_html .= ''; foreach ( $labels as $label ) { - if ( $links && $label['link'] ) { + if ( $links && isset( $label['flag'] ) && $label['link'] ) { $labels_html .= ''; - } else { + } elseif ( isset( $label['flag'] ) ) { $labels_html .= '' . esc_html( $label['flag'] ) . ''; } } @@ -76,14 +76,12 @@ function newspack_display_tag_labels( $labels = null, $links = true ) { endif; /** - * Enqueue scripts. - * - * - Adds label to post title where applicable. + * Adds label to post title where applicable. * * @param string $post_title Title of the post. * @param int $post_id ID of the post. * - * @return null + * @return string */ function newspack_tag_labels_for_post_title( $post_title, $post_id ) { diff --git a/newspack-theme/template-parts/content/content-archive.php b/newspack-theme/template-parts/content/content-archive.php index 4a168eca0..2e429339a 100644 --- a/newspack-theme/template-parts/content/content-archive.php +++ b/newspack-theme/template-parts/content/content-archive.php @@ -17,7 +17,7 @@ // Get tag labels for this post. if ( function_exists( 'newspack_get_tag_labels' ) ) { - $tag_labels = newspack_get_tag_labels( get_the_id() ); + $tag_labels = newspack_get_tag_labels( get_the_ID() ); } ?> diff --git a/newspack-theme/template-parts/content/content-excerpt.php b/newspack-theme/template-parts/content/content-excerpt.php index 4e57403f0..8ddc62c73 100755 --- a/newspack-theme/template-parts/content/content-excerpt.php +++ b/newspack-theme/template-parts/content/content-excerpt.php @@ -17,7 +17,7 @@ // Get tag labels for this post. if ( function_exists( 'newspack_get_tag_labels' ) ) { - $tag_labels = newspack_get_tag_labels( get_the_id() ); + $tag_labels = newspack_get_tag_labels( get_the_ID() ); } ?> diff --git a/newspack-theme/template-parts/header/entry-header.php b/newspack-theme/template-parts/header/entry-header.php index bd78e633b..e4224f3e3 100755 --- a/newspack-theme/template-parts/header/entry-header.php +++ b/newspack-theme/template-parts/header/entry-header.php @@ -15,7 +15,7 @@ // Get tag labels for this post. if ( function_exists( 'newspack_get_tag_labels' ) ) { - $tag_labels = newspack_get_tag_labels( get_the_id() ); + $tag_labels = newspack_get_tag_labels( get_the_ID() ); } // Get page title visibility. From 96a4038ce8d1609f0099aefc40d722b612753784 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 22 Jan 2026 10:55:32 -0700 Subject: [PATCH 06/20] refactor: move tag labels out to separate line --- newspack-theme/inc/newspack-tag-labels.php | 27 ------------------- .../sass/plugins/newspack-tag-labels.scss | 17 +++++++++--- .../content/content-archive.php | 6 ++--- .../content/content-excerpt.php | 6 ++--- .../template-parts/header/entry-header.php | 6 ++--- 5 files changed, 22 insertions(+), 40 deletions(-) diff --git a/newspack-theme/inc/newspack-tag-labels.php b/newspack-theme/inc/newspack-tag-labels.php index e37fa70aa..a1b5f85b1 100644 --- a/newspack-theme/inc/newspack-tag-labels.php +++ b/newspack-theme/inc/newspack-tag-labels.php @@ -75,33 +75,6 @@ function newspack_display_tag_labels( $labels = null, $links = true ) { } endif; -/** - * Adds label to post title where applicable. - * - * @param string $post_title Title of the post. - * @param int $post_id ID of the post. - * - * @return string - */ -function newspack_tag_labels_for_post_title( $post_title, $post_id ) { - - // Apply title changes only to front/home views and non-singular views. - if ( ! class_exists( 'Newspack\Tag_Labels' ) || ( defined( 'WP_CLI' ) && WP_CLI ) || is_admin() || ( is_singular() && ! ( is_front_page() || is_home() ) ) ) { - return $post_title; - } - - $labels = newspack_get_tag_labels( $post_id ); - if ( empty( $labels ) ) { - return $post_title; - } - - // Disable label links, as entire post title will be linked. - $labels_html = newspack_generate_tag_labels( $labels, false ); - - return $labels_html ? ( $labels_html . ' ' . $post_title ) : $post_title; -} -add_filter( 'the_title', 'newspack_tag_labels_for_post_title', 10, 2 ); - /** * Enqueue styles. */ diff --git a/newspack-theme/sass/plugins/newspack-tag-labels.scss b/newspack-theme/sass/plugins/newspack-tag-labels.scss index 39089bbbe..e39dea339 100644 --- a/newspack-theme/sass/plugins/newspack-tag-labels.scss +++ b/newspack-theme/sass/plugins/newspack-tag-labels.scss @@ -12,7 +12,7 @@ a, a:visited { color: #fff; - } + } a:hover { opacity: 0.8; @@ -46,9 +46,18 @@ amp-script .tag-labels { margin-left: 0.5em; } - // Workaround margin override for featured images. - .featured-image-behind .cat-links.tag-labels a { - margin-right: 0.5em; + // Workaround margin/padding override for featured images. + .featured-image-behind { + .cat-links.tag-labels { + a, + a:hover { + padding: 0.3em 0.5em; + margin-right: 0.5em; + } + .tag-label + .tag-label:hover { + margin-left: 0.3em; // Don't collapse multiple labels. + } + } } } diff --git a/newspack-theme/template-parts/content/content-archive.php b/newspack-theme/template-parts/content/content-archive.php index 2e429339a..f001e282d 100644 --- a/newspack-theme/template-parts/content/content-archive.php +++ b/newspack-theme/template-parts/content/content-archive.php @@ -30,10 +30,10 @@ if ( ! empty( $native_sponsors ) ) { // Get label for native post sponsors. newspack_sponsor_label( $native_sponsors ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } if ( $display_sponsors_and_categories ) { - if ( $tag_labels ) { - newspack_display_tag_labels( $tag_labels ); - } newspack_categories(); } } else { diff --git a/newspack-theme/template-parts/content/content-excerpt.php b/newspack-theme/template-parts/content/content-excerpt.php index 8ddc62c73..9246dd2d1 100755 --- a/newspack-theme/template-parts/content/content-excerpt.php +++ b/newspack-theme/template-parts/content/content-excerpt.php @@ -30,10 +30,10 @@ if ( ! empty( $native_sponsors ) ) { // Get label for native post sponsors. newspack_sponsor_label( $native_sponsors ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } if ( $display_sponsors_and_categories ) { - if ( $tag_labels ) { - newspack_display_tag_labels( $tag_labels ); - } newspack_categories(); } } else { diff --git a/newspack-theme/template-parts/header/entry-header.php b/newspack-theme/template-parts/header/entry-header.php index e4224f3e3..4b4b33565 100755 --- a/newspack-theme/template-parts/header/entry-header.php +++ b/newspack-theme/template-parts/header/entry-header.php @@ -34,10 +34,10 @@ if ( ! is_page() ) : if ( ! empty( $native_sponsors ) ) { newspack_sponsor_label( $native_sponsors, null, true ); + if ( $tag_labels ) { + newspack_display_tag_labels( $tag_labels ); + } if ( $display_sponsors_and_categories ) { - if ( $tag_labels ) { - newspack_display_tag_labels( $tag_labels ); - } newspack_categories(); } } else { From ed492ba3161cedb71836a5316bed30147d32b369 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 22 Jan 2026 11:38:53 -0700 Subject: [PATCH 07/20] feat: add tag label color to theme customizer --- newspack-theme/inc/newspack-tag-labels.php | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/newspack-theme/inc/newspack-tag-labels.php b/newspack-theme/inc/newspack-tag-labels.php index a1b5f85b1..7a52517e6 100644 --- a/newspack-theme/inc/newspack-tag-labels.php +++ b/newspack-theme/inc/newspack-tag-labels.php @@ -90,3 +90,75 @@ function newspack_tag_labels_enqueue_styles() { ); } add_action( 'wp_enqueue_scripts', 'newspack_tag_labels_enqueue_styles' ); + +/** + * Adds section to customizer for Tag Labels options. + * + * @param WP_Customize_Manager $wp_customize Customizer object. + */ +function newspack_tag_labels_customize_register( $wp_customize ) { + $wp_customize->add_section( + 'newspack_tag_labels', + array( + 'title' => esc_html__( 'Tag Labels', 'newspack-theme' ), + ) + ); + + $wp_customize->add_setting( + 'tag_labels_hex', + array( + 'default' => '#FED850', + 'sanitize_callback' => 'sanitize_hex_color', + ) + ); + + $wp_customize->add_control( + new WP_Customize_Color_Control( + $wp_customize, + 'tag_labels_hex', + array( + 'label' => esc_html__( 'Tag Label', 'newspack-theme' ), + 'description' => esc_html__( 'Changes the background of the tag label that appears on posts and blocks. It should stand out boldly against your site\'s color scheme.', 'newspack-theme' ), + 'section' => 'newspack_tag_labels', + ) + ) + ); +} +add_action( 'customize_register', 'newspack_tag_labels_customize_register' ); + +/** + * Add custom colors to tag labels. + */ +function newspack_tag_labels_styles() { + $flag_color = get_theme_mod( 'tag_labels_hex', '#FED850' ); + $flag_color_contrast = newspack_get_color_contrast( $flag_color ); + ?> + + Date: Fri, 23 Jan 2026 12:57:25 -0700 Subject: [PATCH 08/20] feat: add block and editor styles --- newspack-theme/inc/newspack-tag-labels.php | 10 ++++++ .../plugins/newspack-tag-labels-editor.scss | 31 +++++++++++++++++++ .../sass/plugins/newspack-tag-labels.scss | 23 +++++++++----- scripts/compile-scss.js | 4 +++ 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 newspack-theme/sass/plugins/newspack-tag-labels-editor.scss diff --git a/newspack-theme/inc/newspack-tag-labels.php b/newspack-theme/inc/newspack-tag-labels.php index 7a52517e6..44a5d2cf2 100644 --- a/newspack-theme/inc/newspack-tag-labels.php +++ b/newspack-theme/inc/newspack-tag-labels.php @@ -91,6 +91,15 @@ function newspack_tag_labels_enqueue_styles() { } add_action( 'wp_enqueue_scripts', 'newspack_tag_labels_enqueue_styles' ); +/** + * Enqueue supplemental block editor styles. + */ +function newspack_tag_labels_editor_styles() { + wp_enqueue_style( 'newspack-tag-labels-editor-styles', get_theme_file_uri( '/styles/newspack-tag-labels-editor.css' ), false, wp_get_theme()->get( 'Version' ), 'all' ); +} +add_action( 'enqueue_block_editor_assets', 'newspack_tag_labels_editor_styles' ); + + /** * Adds section to customizer for Tag Labels options. * @@ -136,6 +145,7 @@ function newspack_tag_labels_styles() {