Files
chrnx-dev-wp/inc/setup.php
T
chrnxandClaude Opus 5 13a8b0425f fix: keep the block title tag and drop Rank Math's relocated copy
Rank Math moves _wp_render_title_tag off wp_head into its own
rank_math/head block, but it does not know about the block-theme renderer
that replaced it, so both rendered. The previous release removed the
block renderer and kept the relocated one, which fixed the duplicate but
left the page depending on a plugin that may print nothing at all: Rank
Math skips its entire frontend until its setup wizard completes, and in
that state the page had no <title> and no social tags.

Remove the relocated copy instead. Both carry the same text, since Rank
Math supplies it through pre_get_document_title, and the block renderer
survives when the plugin is absent or silent. The removal needs no guard:
with no Rank Math, rank_math/head holds no callbacks.

For the same reason chrnx_has_seo_plugin() now asks whether an SEO plugin
actually printed its head, not whether one happens to be installed.

Verified against a real Rank Math install in all three states: emitting,
installed but silent, and absent. One title every time, never zero.

The subscribe call to action now also runs on Pages and archives, so the
Journal and the topic archives can convert, and it skips the Subscribe
page itself rather than linking there from there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-14 09:51:03 -05:00

120 lines
3.8 KiB
PHP

<?php
/**
* Theme setup.
*
* @package CHRNX
*/
/**
* Register the theme's core WordPress features.
*/
function chrnx_setup() {
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'editor-styles' );
add_editor_style( array( 'assets/css/base.css', 'assets/css/layout.css', 'assets/css/components.css' ) );
remove_action( 'wp_footer', 'the_block_template_skip_link' );
add_image_size( 'chrnx-card', 720, 480, true );
register_nav_menus(
array(
'chrnx-primary' => __( 'Primary navigation', 'chrnx' ),
'chrnx-footer' => __( 'Footer navigation', 'chrnx' ),
)
);
// No template renders a comment thread, so nothing is collected silently.
remove_post_type_support( 'post', 'comments' );
remove_post_type_support( 'page', 'comments' );
}
add_action( 'after_setup_theme', 'chrnx_setup' );
add_filter( 'comments_open', '__return_false' );
/**
* Print Open Graph and Twitter card tags only when nothing else does.
*
* ponytail: an installed SEO plugin already emits these per post, with the
* right title and image. Two sets of og: tags let crawlers pick the wrong one,
* so the theme yields and only covers the no-plugin case.
*/
function chrnx_print_social_meta() {
if ( chrnx_has_seo_plugin() ) {
return;
}
if ( is_singular() ) {
$title = get_the_title();
$url = get_permalink();
$description = wp_strip_all_tags( get_the_excerpt() );
$type = 'article';
$image_id = get_post_thumbnail_id();
} else {
$title = get_bloginfo( 'name' );
$url = home_url( '/' );
$description = get_bloginfo( 'description' );
$type = 'website';
$image_id = 0;
}
// Generated derivative, not the design master: masters are not shipped.
$image = $image_id
? wp_get_attachment_image_url( $image_id, 'full' )
: get_theme_file_uri( 'assets/images/generated/about-grunge-1536.webp' );
$tags = array(
'og:site_name' => get_bloginfo( 'name' ),
'og:type' => $type,
'og:title' => $title,
'og:description' => $description,
'og:url' => $url,
'og:image' => $image,
);
foreach ( $tags as $property => $content ) {
if ( '' === $content ) {
continue;
}
printf(
'<meta property="%1$s" content="%2$s" />' . "\n",
esc_attr( $property ),
esc_attr( $content )
);
}
echo '<meta name="twitter:card" content="summary_large_image" />' . "\n";
}
add_action( 'wp_head', 'chrnx_print_social_meta' );
/**
* Report whether an SEO plugin already printed the document head.
*
* Deliberately not "is one installed": Rank Math skips its whole frontend
* until its setup wizard completes, so an installed-but-silent plugin used to
* make the theme yield to nobody. rank_math/head fires only when it really
* rendered, and it runs at wp_head priority 1, ahead of the tags below.
*
* @return bool True when an SEO plugin printed its head block.
*/
function chrnx_has_seo_plugin(): bool {
return did_action( 'rank_math/head' ) > 0;
}
/**
* Drop the relocated copy of core's title tag.
*
* Rank Math moves _wp_render_title_tag off wp_head and into its own
* rank_math/head block, but it does not know about the block-theme renderer
* that replaced it, so block themes render two identical <title> elements.
*
* Remove the relocated copy, never the block one. Both carry the same text,
* because Rank Math supplies it through pre_get_document_title, and keeping
* the block renderer means a page still has a title when the plugin is
* absent or silent. No guard is needed: with no Rank Math, rank_math/head
* holds no callbacks and this is a no-op.
*/
function chrnx_remove_duplicate_title_tag() {
remove_action( 'rank_math/head', '_wp_render_title_tag', 1 );
}
add_action( 'wp_head', 'chrnx_remove_duplicate_title_tag', 0 );