Weil ich mehrere Microblogging-Kategorien habe, die keine Titel brauchen, hier ein Fix für das Erstellen eines Pseudotitels für SEO, GEO, und Social-Media-Links:
// Shared function for title-less posts in certain categories
function mb_title_for_titleless_notes( $title ) {
if ( ! is_singular( 'post' ) ) {
return $title;
}
global $post;
// Only act if the post has no title
if ( trim( $post->post_title ) !== '' ) {
return $title;
}
// Get categories
$categories = get_the_category( $post->ID );
if ( empty( $categories ) ) {
return $title;
}
// Allowed categories
$allowed = [ 'macht', 'notiert', 'liest', 'hoert', 'schaut', 'spielt' ];
$matched_category = null;
foreach ( $categories as $cat ) {
if ( in_array( $cat->slug, $allowed, true ) ) {
$matched_category = $cat;
break;
}
}
if ( ! $matched_category ) {
return $title;
}
// Build replacement title
$date = get_the_date( 'j. F Y, G:i', $post ); // German
$category_name = $matched_category->name;
// Example: "Notiert: 9. Januar 2026, 9:46 Uhr - Mario Breskic"
return sprintf(
'%s: %s Uhr - Mario Breskic',
$category_name,
$date
);
}
// HTML <title>
add_filter( 'wpseo_title', 'mb_title_for_titleless_notes', 20 );
// Open Graph <meta property="og:title">
add_filter( 'wpseo_opengraph_title', 'mb_title_for_titleless_notes', 20 );
// Twitter <meta name="twitter:title">
add_filter( 'wpseo_twitter_title', 'mb_title_for_titleless_notes', 20 );
// Built with ChatGPT
Schreibe einen Kommentar