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>
This commit is contained in:
26 files changed
+47
-37
No files matched your search
+18
-15
@@ -87,30 +87,33 @@ function chrnx_print_social_meta() {
|
||||
add_action( 'wp_head', 'chrnx_print_social_meta' );
|
||||
|
||||
/**
|
||||
* Report whether an SEO plugin owns the document head.
|
||||
* Report whether an SEO plugin already printed the document head.
|
||||
*
|
||||
* @return bool True when a known SEO plugin is active.
|
||||
* 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 defined( 'RANK_MATH_VERSION' ) || defined( 'WPSEO_VERSION' ) || defined( 'SEOPRESS_VERSION' );
|
||||
return did_action( 'rank_math/head' ) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop core's title tag when an SEO plugin prints its own.
|
||||
* Drop the relocated copy of core's title tag.
|
||||
*
|
||||
* Both were rendering, so every page shipped two <title> elements. Block
|
||||
* themes swap _wp_render_title_tag for the block-template renderer, so
|
||||
* removing only the classic one silently did nothing here.
|
||||
* 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.
|
||||
*
|
||||
* locate_block_template() registers that renderer during template_include,
|
||||
* after both `wp` and template_redirect, so wp_head is the first hook where
|
||||
* it exists and can still be removed before it runs.
|
||||
* 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() {
|
||||
if ( ! chrnx_has_seo_plugin() ) {
|
||||
return;
|
||||
}
|
||||
remove_action( 'wp_head', '_block_template_render_title_tag', 1 );
|
||||
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
|
||||
remove_action( 'rank_math/head', '_wp_render_title_tag', 1 );
|
||||
}
|
||||
add_action( 'wp_head', 'chrnx_remove_duplicate_title_tag', 0 );
|
||||
Reference in new issue
Block a user