Please or Register to create posts and topics.

Update für: Google strukturierte Daten für Diskussionsforen ?

Hey,

bei mir bemängelt Google SEO ständig fehlende Strukturdaten im Forum. Die Fehlermeldung ist die folgende:

“Auf mehr als 100 deiner Forumsseiten fehlen strukturierte Daten für Diskussionsforen

Wenn du solche Daten implementierst, kann Google in relevanten Suchergebnis-Spezialformaten entsprechende Onlinediskussionen auf deiner Website identifizieren und anzeigen”
Ich hab daraufhin versucht, es mit Änderungen am functions.php hinzubekommen, wobei ich Hilfe von der Claude KI hatte. Kompletter Blindflug leider, da ich keine Ahnung vom Programmieren hab. Es hat dann auch nicht funktioniert, leider.
Kann man diese Funktion bitte nachrüsten ? Google SEO hat hohe Priorität.
Claude hat folgende Ergänzung vorgeschlagen:
—————————– code clode KI ———————————————

// DiscussionForumPosting Structured Data für Asgaros Forum
// Einfach ans Ende der functions.php einfügen (OHNE <?php davor)

add_action( ‘wp_footer’, ‘asgaros_discussionforum_schema’, 99 );

function asgaros_discussionforum_schema() {
global $wpdb;

// Topic-Slug aus der aktuellen URL holen
$request_uri = isset( $_SERVER[‘REQUEST_URI’] ) ? $_SERVER[‘REQUEST_URI’] : ”;

// Nur auf /forum/topic/… Seiten ausführen
if ( ! preg_match( ‘#/forum/topic/([^/]+)#’, $request_uri, $matches ) ) {
return;
}

$topic_slug = sanitize_title( $matches[1] );

if ( empty( $topic_slug ) ) {
return;
}

// Tabellennamen (Standard-Präfix wp_ – passt für die meisten Installationen)
$prefix = $wpdb->prefix;
$topics_table = $prefix . ‘asgarosforum_topics’;
$posts_table = $prefix . ‘asgarosforum_posts’;

// Topic anhand des Slugs suchen
$topic = $wpdb->get_row(
$wpdb->prepare(
“SELECT id, name, author_id, date, slug
FROM {$topics_table}
WHERE slug = %s
LIMIT 1″,
$topic_slug
)
);

// Falls kein Treffer per Slug, per ID versuchen (falls Slug numerisch)
if ( empty( $topic ) && is_numeric( $topic_slug ) ) {
$topic = $wpdb->get_row(
$wpdb->prepare(
“SELECT id, name, author_id, date
FROM {$topics_table}
WHERE id = %d
LIMIT 1″,
intval( $topic_slug )
)
);
}

if ( empty( $topic ) ) {
return;
}

$topic_id = intval( $topic->id );

// Topic-URL
$topic_url = home_url( ‘/forum/topic/’ . $topic_slug . ‘/’ );

// Autor
$author = get_userdata( $topic->author_id );
$author_name = $author ? $author->display_name : ‘Unbekannt’;

// Datum ISO 8601
$date_published = date( ‘c’, strtotime( $topic->date ) );

// Alle Posts dieses Topics laden
$all_posts = $wpdb->get_results(
$wpdb->prepare(
“SELECT id, text, author_id, date
FROM {$posts_table}
WHERE parent_id = %d
ORDER BY id ASC
LIMIT 50″,
$topic_id
)
);

if ( empty( $all_posts ) ) {
return;
}

// Erster Post = Topic-Text
$first_post = array_shift( $all_posts );
$topic_text = mb_substr( wp_strip_all_tags( stripslashes( $first_post->text ) ), 0, 500 );

// Restliche Posts = Antworten/Kommentare
$comments_schema = array();
foreach ( $all_posts as $reply ) {
$reply_author = get_userdata( $reply->author_id );
$reply_author_name = $reply_author ? $reply_author->display_name : ‘Unbekannt’;
$comments_schema[] = array(
‘@type’ => ‘Comment’,
‘dateCreated’ => date( ‘c’, strtotime( $reply->date ) ),
‘text’ => mb_substr( wp_strip_all_tags( stripslashes( $reply->text ) ), 0, 300 ),
‘author’ => array(
‘@type’ => ‘Person’,
‘name’ => $reply_author_name,
),
);
}

// Schema zusammenbauen
$schema = array(
‘@context’ => ‘https://schema.org’,
‘@type’ => ‘DiscussionForumPosting’,
‘headline’ => stripslashes( $topic->name ),
‘text’ => $topic_text,
‘url’ => $topic_url,
‘datePublished’ => $date_published,
‘author’ => array(
‘@type’ => ‘Person’,
‘name’ => $author_name,
),
‘interactionStatistic’ => array(
‘@type’ => ‘InteractionCounter’,
‘interactionType’ => ‘https://schema.org/CommentAction’,
‘userInteractionCount’ => count( $comments_schema ),
),
);

if ( ! empty( $comments_schema ) ) {
$schema[‘comment’] = $comments_schema;
}

echo “\n” . ‘<script type=”application/ld+json”>’ . “\n”;
echo wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT );
echo “\n” . ‘</script>’ . “\n”;
}

—————— Hinweis von Claude an den Programmierer ————————————-

Briefing für den Programmierer:

WordPress-Blog 25u.de mit Asgaros Forum Plugin. Google Search Console meldet fehlendes DiscussionForumPosting Schema auf allen Forumsseiten. Ziel: PHP-Snippet in functions.php das auf jeder Asgaros Topic-Seite automatisch ein korrektes JSON-LD Schema ausgibt. Ansatz ist fertig entwickelt, scheitert nur daran dass der genaue Asgaros-Tabellenname und die URL-zu-Topic-Zuordnung noch nicht stimmen. Code-Vorlage vorhanden.


Die Vorlage die wir erarbeitet haben kannst du ihm als Startpunkt mitgeben — das spart ihm die Hälfte der Arbeit.

Und das Konzept sitzt: sobald es läuft, profitieren automatisch alle 100+ Forumsseiten davon ohne dass du nochmal Hand anlegen musst. Viel Erfolg!