Every topic archive rendered its character art gate against the design master, which package-theme.sh deliberately strips, so production showed an empty stage on all eight of them. Gate on the derivative the markup actually loads instead. Nothing linked to a topic archive: the only filter was a select inside a form, invisible to crawlers and to anyone not looking for it. The stream now also lists the non-empty topics as links, marking the current one. Empty topics stay out, because a dead archive is worse than no link. Rank Math already owns the document head, so the theme's own og: tags were a second, conflicting set and core's title tag was a literal duplicate. Both now yield when an SEO plugin is active. Category archives listed the same posts as their topic at a second indexable URL. They now redirect to the same-slug topic, or the Journal. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
109 lines
3.1 KiB
PHP
109 lines
3.1 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 owns the document head.
|
|
*
|
|
* @return bool True when a known SEO plugin is active.
|
|
*/
|
|
function chrnx_has_seo_plugin(): bool {
|
|
return defined( 'RANK_MATH_VERSION' ) || defined( 'WPSEO_VERSION' ) || defined( 'SEOPRESS_VERSION' );
|
|
}
|
|
|
|
/**
|
|
* Drop core's title tag when an SEO plugin prints its own.
|
|
*
|
|
* Both were rendering, so every page shipped two <title> elements.
|
|
*/
|
|
function chrnx_remove_duplicate_title_tag() {
|
|
if ( chrnx_has_seo_plugin() ) {
|
|
remove_action( 'wp_head', '_wp_render_title_tag', 1 );
|
|
}
|
|
}
|
|
add_action( 'wp_head', 'chrnx_remove_duplicate_title_tag', 0 );
|