fix: declare the language each post is actually written in

Half the journal is Spanish, but every route declared en-US, so screen
readers pronounced Spanish posts with English phonetics and crawlers
indexed them as English. The chrnx_language taxonomy already recorded the
answer per post and nothing read it.

Map its terms onto the html lang attribute for single posts and for the
language archives, replacing only the language so dir and any plugin
attribute survive. Posts with no language term keep the site default.

Also stop advertising a comments feed. Comments are unsupported theme-wide,
yet the head still linked one, because feed_links_extra also fires for old
posts carrying a non-zero comment_count. The core filter covers both that
and the site-wide link while leaving topic, author and search feeds alone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
chrnxandClaude Opus 5 committed 2026-08-14 19:05:55 -05:00
1 parent a4c68e3c56
commit 0a90e78783
2 files changed
+133

No files matched your search

+77
View File
@@ -37,6 +37,83 @@ class ThemeSetupTest extends WP_UnitTestCase {
$this->assertContains( 'assets/css/components.css', $editor_styles );
}
/**
* Ensure a Spanish post declares a Spanish document language.
*/
public function test_language_attributes_follow_a_spanish_post() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
$this->go_to( get_permalink( $post_id ) );
$this->assertTrue( is_singular( 'post' ) );
$this->assertSame( 'lang="es-MX"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure an English post keeps the English document language.
*/
public function test_language_attributes_follow_an_english_post() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'en', 'chrnx_language' );
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure the direction attribute survives the language swap.
*/
public function test_language_attributes_preserve_other_attributes() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( 'lang="es-MX" dir="ltr"', chrnx_filter_language_attributes( 'lang="en-US" dir="ltr"' ) );
}
/**
* Ensure a post without a language term is left untouched.
*/
public function test_language_attributes_ignore_a_post_without_a_language() {
$post_id = self::factory()->post->create();
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure a language archive declares the language it lists.
*/
public function test_language_attributes_follow_a_language_archive() {
$post_id = self::factory()->post->create();
wp_set_object_terms( $post_id, 'es', 'chrnx_language' );
$this->go_to( get_term_link( 'es', 'chrnx_language' ) );
$this->assertTrue( is_tax( 'chrnx_language' ) );
$this->assertSame( 'lang="es-MX"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure the home page keeps the site language.
*/
public function test_language_attributes_leave_the_home_page_alone() {
$this->go_to( home_url( '/' ) );
$this->assertSame( 'lang="en-US"', chrnx_filter_language_attributes( 'lang="en-US"' ) );
}
/**
* Ensure the head never advertises a comments feed the theme cannot render.
*/
public function test_comments_feed_is_not_advertised() {
$this->assertFalse( apply_filters( 'feed_links_show_comments_feed', true ) );
}
/**
* Ensure the local base stylesheet is enqueued with the theme version.
*/