Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6287b21
feat: add theme support for tags as labels
jason10lee Jan 7, 2026
c9835a2
fix: continuity checks for tag labels support
jason10lee Jan 7, 2026
3c78f8b
fix: separate consecutive labels
jason10lee Jan 7, 2026
1dfc474
fix: apply suggestions from Copilot code review
jason10lee Jan 8, 2026
54fcccb
fix: tweaks; Copilot suggestions
jason10lee Jan 8, 2026
96a4038
refactor: move tag labels out to separate line
jason10lee Jan 22, 2026
ed492ba
feat: add tag label color to theme customizer
jason10lee Jan 22, 2026
fcb3b67
feat: add block and editor styles
jason10lee Jan 23, 2026
abbb6a0
fix: apply Copilot suggestions
jason10lee Jan 24, 2026
3f55f2e
fix: skip styles if Tag Labels support not present
jason10lee Jan 24, 2026
6b9b843
fix: enable RTL conversion for tag label CSS
jason10lee Jan 24, 2026
de3bed7
refactor: centralized HTML generation function and interface to `news…
jason10lee Mar 30, 2026
1a3df39
style: new lint from old code
jason10lee Mar 30, 2026
ef8091f
Merge trunk into feat/tag-labels and resolve conflicts
Copilot Apr 23, 2026
ef7dcd6
fix: bump tag-labels flag specificity over wpnbha/wpnbpc
jason10lee May 26, 2026
62ec20e
fix: initialize $tag_labels so reads are safe without the Newspack pl…
jason10lee May 26, 2026
b7fd4b4
fix: exempt tag-labels from archive + Jetpack cat-links suppression
jason10lee May 26, 2026
9257154
fix: restore wp_kses_post on $subtitle in entry-header.php
jason10lee May 26, 2026
ab27387
fix: register RTL variants for tag-labels stylesheets
jason10lee May 26, 2026
09da3a8
docs: correct misleading phpcs:ignore rationale on subtitle echoes
jason10lee May 26, 2026
2ac4b26
fix: bump tag-labels flag specificity over wpnbha/wpnbpc on frontend
jason10lee May 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions newspack-theme/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -224,6 +225,7 @@ function newspack_setup() {
),
)
);
// phpcs:enable Squiz.Commenting.InlineComment.InvalidEndChar

add_theme_support(
'editor-gradient-presets',
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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' ),
Expand Down Expand Up @@ -814,6 +817,8 @@ function newspack_check_current_template() {
*
* The 'admin-color-' prefix is used to make sure the classes get moved to the <body> 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' ) ) {
Expand Down Expand Up @@ -974,6 +979,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 ) {
Expand Down Expand Up @@ -1123,17 +1131,21 @@ 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.
if ( strlen( $content ) <= $length ) {
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;
}
Expand Down Expand Up @@ -1200,9 +1212,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( '<span class="page-description">', $title, 2 );
$title_format = get_theme_mod( 'archive_title_format', 'default' );

Expand Down Expand Up @@ -1334,6 +1348,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.
*/
Expand Down Expand Up @@ -1364,4 +1385,3 @@ function newspack_dequeue_mediaelement() {
* Woo Templates cache handling
*/
require get_template_directory() . '/woocommerce/templates.php';

2 changes: 1 addition & 1 deletion newspack-theme/inc/jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function newspack_jetpack_setup() {
'post-details' => array(
'stylesheet' => 'newspack-style',
'date' => '.posted-on',
'categories' => '.cat-links:not(.sponsor-label)',
'categories' => '.cat-links:not(.sponsor-label):not(.tag-labels)',
'tags' => '.tags-links',
'author' => '.byline:not(.sponsor-byline), .author-avatar',
),
Expand Down
178 changes: 178 additions & 0 deletions newspack-theme/inc/newspack-tag-labels.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<?php
/**
* Newspack Tag Labels shim
*
* @package Newspack
*/

if ( ! function_exists( 'newspack_get_tag_labels' ) ) :
/**
* Returns array of tag labels for the given post.
*
* @param int|WP_Post|null $post Post to check.
*
* @return array|null
*/
function newspack_get_tag_labels( $post = null ) {

if ( class_exists( '\Newspack\Tag_Labels' ) && method_exists( '\Newspack\Tag_Labels', 'get_labels_for_post' ) ) {
return \Newspack\Tag_Labels::get_labels_for_post( $post );
}

return null;
}
endif;


if ( ! function_exists( 'newspack_generate_tag_labels' ) ) :
/**
* Generates HTML for given tag labels.
*
* @param array $labels Labels to display.
* @param bool $links Whether to include links to tag archives.
* @param array $outer_classes Classes to apply to the outer container.
* @param array $inner_classes Classes to apply to the inner container.
*
* @return string Tag labels as HTML.
*/
function newspack_generate_tag_labels( $labels = null, $links = true, $outer_classes = array( 'tag-labels' ), $inner_classes = array( 'tag-label', 'flag' ) ) {
if ( class_exists( '\Newspack\Tag_Labels' ) && method_exists( '\Newspack\Tag_Labels', 'generate_html' ) ) {
return \Newspack\Tag_Labels::generate_html( $labels, $links, $outer_classes, $inner_classes, 'span' );
}

return '';
}
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 ( class_exists( '\Newspack\Tag_Labels' ) && method_exists( '\Newspack\Tag_Labels', 'display' ) ) {
\Newspack\Tag_Labels::display( $labels, $links, 'span' );
}

return null;
}
endif;

/**
* 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' )
);
wp_style_add_data( 'newspack-tag-labels-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'newspack_tag_labels_enqueue_styles' );

/**
* Enqueue supplemental block editor styles.
*/
function newspack_tag_labels_editor_styles() {
Comment thread
jason10lee marked this conversation as resolved.
if ( ! class_exists( 'Newspack\Tag_Labels' ) ) {
return;
}
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' );
wp_style_add_data( 'newspack-tag-labels-editor-styles', 'rtl', 'replace' );
}
add_action( 'enqueue_block_editor_assets', 'newspack_tag_labels_editor_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 ) {
if ( ! class_exists( 'Newspack\Tag_Labels' ) ) {
return;
}

$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() {
if ( ! class_exists( 'Newspack\Tag_Labels' ) ) {
return;
}

$flag_color = get_theme_mod( 'tag_labels_hex', '#FED850' );
$flag_color_contrast = newspack_get_color_contrast( $flag_color );
?>
<style>
.tag-labels .flag,
amp-script .tag-labels .flag,
.wpnbha .tag-labels a.flag,
.featured-image-behind .tag-labels a.flag {
background: <?php echo esc_attr( $flag_color ); ?>;
color: <?php echo esc_attr( $flag_color_contrast ); ?>;
}
</style>
<?php
}
add_action( 'wp_head', 'newspack_tag_labels_styles' );

/**
* Add custom colors for tag labels to editor.
*/
function newspack_tag_labels_styles_editor() {
if ( ! class_exists( 'Newspack\Tag_Labels' ) ) {
return;
}

$flag_color = get_theme_mod( 'tag_labels_hex', '#FED850' );
$flag_color_contrast = newspack_get_color_contrast( $flag_color );

$tag_labels_customizations = '
.editor-styles-wrapper .tag-labels .flag {
background: ' . esc_attr( $flag_color ) . ';
color: ' . esc_attr( $flag_color_contrast ) . ';
}
';

wp_add_inline_style( 'newspack-tag-labels-editor-styles', $tag_labels_customizations );
}
add_action( 'enqueue_block_editor_assets', 'newspack_tag_labels_styles_editor' );
Comment thread
jason10lee marked this conversation as resolved.
32 changes: 32 additions & 0 deletions newspack-theme/sass/plugins/newspack-tag-labels-editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@use "../variables-site/variables-site";
@use "../mixins/mixins-main";
@use "../variables-site/structure";

// Newspack Blocks
.tag-labels {
// Use `.tag-label.flag` so this beats `.wpnbha .cat-links a` / `.wpnbpc .cat-links a` on specificity.
.tag-label.flag {
background: var(--newspack-theme-color-highlight);
color: var(--newspack-theme-color-text-main);
line-height: 1;
padding: 0.3em 0.5em;
Comment thread
jason10lee marked this conversation as resolved.
text-transform: uppercase;
}
}

.block-editor {
article {
.tag-labels,
.cat-links:has(+ .tag-labels) {
display: inline-flex;
}
.tag-label + .tag-label {
margin-left: 0.3em; // Don't collapse multiple labels.
}
.tag-labels a,
.tag-labels a:hover {
padding: 0.3em 0.5em;
text-decoration: none;
}
}
}
Loading
Loading