Fehlerhafte Umlaute in WordPress

Nach dem Update einer älteren WordPress-Installation, die auf einer mySQL 4.0 Datenbank lief und nun auf mySQL 5.0 umgestellt wurde, traten bei einem WordPress Blog fehlerhafte Umlaute und Sonderzeichen auf.

So wurde beispielsweise im Browser anstatt einem „ö“ einfach das Zeichen „ö“ angezeigt. Aus einem „ä“ wurde ein „ä“, aus einem „ß“ wurde ein „ß“ usw. Auftreten kann dieses Umlautproblem bei WordPress auch nach einem Serverumzug, wenn sich die PHP- oder MYSQL-Versionen ändern.

In meinem Fall hier war das Problem, das die vorhandene alte Datenbank mit dem Zeichensatz latin1_swedish_ci kodiert war. Das gibt es häufig noch bei älteren WordPress-Versionen vor Version 2.9. In der neueren Mysql 5 Datenbank wurde aber nun als Kodierung uft-8 angelegt. Das führte also zu Problemen. Das „latin1″ entspricht der Zeichenkodierung ISO-8859-1. Im Quellcode der Website findet man den Befehl <meta http-equiv=“Content-Type“ content=“text/html;charset=ISO-8859-1″>.

Inzwischen ist die Standard-Kodierung beim Anlegen einer neuen WordPress-Installationen bereits UTF-8 bzw. UTF8mb4. Das entspricht der HTML5-Spezifikation und im Quellcode der Website sollte dann der Befehl <meta charset=“UTF-8″> auftauchen.

Eine Lösung über wp-config.php

Oft genügt es die Datei wp-config.php im WordPress-Hauptverzeichnis zu öffnen (bitte vorher in jedem Fall eine Sicherung der Datei anlegen!) und dann den benötigten alten Zeichensatz einfügen, z.B. define(‚DB_CHARSET‘, ‚latin1‘);   oder define(‚DB_CHARSET‘, ‚utf8‘); …das sieht dann so aus:

define('DB_CHARSET', 'latin1');

Es kann sein, das sich in der Datei schon eine bestehende Zeile für den DB-CHARSET der aktuellen Datenbank befindet. Diese Zeile müsste man auskommentieren (durch die // Striche vorne weg), damit sie nicht verwendet wird.

// define('DB_CHARSET', 'utf8');

Nun würde in diesem Fall die Kodierung der Datenbank wieder auf „latin-1“ erfolgen. Aber je nachdem, welche Kodierung bei Deiner alten Datenbank verwendet wurde, ist der DB_CHARSET entsprechend anzupassen.

Charset-Änderungen in der WordPress-Datenbank vornehmen

Zwar wird nach dem Einfügen der latin1 Charset meistens erstmal alles wieder korrekt in WordPress angezeigt, in der Datenbank bleiben die fehlerhaften Zeichen aber dennoch bestehen. Natürlich kann man mit einigen Befehlen die fehlerhaften Umlaute und Sonderzeichen wieder dauerhaft umstellen. Wichtig: Vorab unbedingt eine Sicherung der Datenbank machen! Als erstes sollte hier in der wp-config wieder auf UTF-8 umgestellt werden. Also folgendes einfügen:

define('DB_CHARSET', 'utf8');

Man öffnet nun in phpAdmin die entsprechende Datenbank mit der WordPress-Installation. Über den Tab “SQL”können SQL-Befehle direkt in einer Datenbank ausgeführt werden. Wir geben also folgenden SQL-Befehl ein:

UPDATE wp_categories SET category_description = replace(category_description, 'ä', 'ä');
UPDATE wp_categories SET category_description = replace(category_description, 'Ä', 'Ä');
UPDATE wp_categories SET category_description = replace(category_description, 'ü', 'ü');
UPDATE wp_categories SET category_description = replace(category_description, 'Ãœ', 'Ü');
UPDATE wp_categories SET category_description = replace(category_description, 'ö', 'ö');
UPDATE wp_categories SET category_description = replace(category_description, 'Ö', 'Ö');
UPDATE wp_categories SET category_description = replace(category_description, 'ß', 'ß');
UPDATE wp_categories SET category_description = replace(category_description, 'ß', 'ß');
UPDATE wp_categories SET category_description = replace(category_description, '°', '°');
UPDATE wp_categories SET category_description = replace(category_description, '©', '©');
UPDATE wp_categories SET category_description = replace(category_description, '€', '€');
UPDATE wp_categories SET cat_name = replace(cat_name, 'ä', 'ä');
UPDATE wp_categories SET cat_name = replace(cat_name, 'Ä', 'Ä');
UPDATE wp_categories SET cat_name = replace(cat_name, 'ü', 'ü');
UPDATE wp_categories SET cat_name = replace(cat_name, 'Ãœ', 'Ü');
UPDATE wp_categories SET cat_name = replace(cat_name, 'ö', 'ö');
UPDATE wp_categories SET cat_name = replace(cat_name, 'Ö', 'Ö');
UPDATE wp_categories SET cat_name = replace(cat_name, 'ß', 'ß');
UPDATE wp_categories SET cat_name = replace(cat_name, 'ß', 'ß');
UPDATE wp_categories SET cat_name = replace(cat_name, '°', '°');
UPDATE wp_categories SET cat_name = replace(cat_name, '©', '©');
UPDATE wp_categories SET cat_name = replace(cat_name, '€', '€');
UPDATE wp_comments SET comment_author = replace(comment_author, 'ä', 'ä');
UPDATE wp_comments SET comment_author = replace(comment_author, 'Ä', 'Ä');
UPDATE wp_comments SET comment_author = replace(comment_author, 'ü', 'ü');
UPDATE wp_comments SET comment_author = replace(comment_author, 'Ãœ', 'Ü');
UPDATE wp_comments SET comment_author = replace(comment_author, 'ö', 'ö');
UPDATE wp_comments SET comment_author = replace(comment_author, 'Ã-', 'Ö');
UPDATE wp_comments SET comment_author = replace(comment_author, 'ß', 'ß');
UPDATE wp_comments SET comment_author = replace(comment_author, 'ß', 'ß');
UPDATE wp_comments SET comment_author = replace(comment_author, '°', '°');
UPDATE wp_comments SET comment_author = replace(comment_author, '©', '©');
UPDATE wp_comments SET comment_author = replace(comment_author, '€', '€');
UPDATE wp_comments SET comment_content = replace(comment_content, 'ä', 'ä');
UPDATE wp_comments SET comment_content = replace(comment_content, 'Ä', 'Ä');
UPDATE wp_comments SET comment_content = replace(comment_content, 'ü', 'ü');
UPDATE wp_comments SET comment_content = replace(comment_content, 'Ãœ', 'Ü');
UPDATE wp_comments SET comment_content = replace(comment_content, 'ö', 'ö');
UPDATE wp_comments SET comment_content = replace(comment_content, 'Ö', 'Ö');
UPDATE wp_comments SET comment_content = replace(comment_content, 'ß', 'ß');
UPDATE wp_comments SET comment_content = replace(comment_content, 'ß', 'ß');
UPDATE wp_comments SET comment_content = replace(comment_content, '°', '°');
UPDATE wp_comments SET comment_content = replace(comment_content, '©', '©');
UPDATE wp_comments SET comment_content = replace(comment_content, '€', '€');
UPDATE wp_links SET link_description = replace(link_description, 'ä', 'ä');
UPDATE wp_links SET link_description = replace(link_description, 'Ä', 'Ä');
UPDATE wp_links SET link_description = replace(link_description, 'ü', 'ü');
UPDATE wp_links SET link_description = replace(link_description, 'Ãœ', 'Ü');
UPDATE wp_links SET link_description = replace(link_description, 'ö', 'ö');
UPDATE wp_links SET link_description = replace(link_description, 'Ã-', 'Ö');
UPDATE wp_links SET link_description = replace(link_description, 'ß', 'ß');
UPDATE wp_links SET link_description = replace(link_description, 'ß', 'ß');
UPDATE wp_links SET link_description = replace(link_description, '°', '°');
UPDATE wp_links SET link_description = replace(link_description, '©', '©');
UPDATE wp_links SET link_description = replace(link_description, '€', '€');
UPDATE wp_links SET link_name = replace(link_name, 'ä', 'ä');
UPDATE wp_links SET link_name = replace(link_name, 'Ä', 'Ä');
UPDATE wp_links SET link_name = replace(link_name, 'ü', 'ü');
UPDATE wp_links SET link_name = replace(link_name, 'Ãœ', 'Ü');
UPDATE wp_links SET link_name = replace(link_name, 'ö', 'ö');
UPDATE wp_links SET link_name = replace(link_name, 'Ö', 'Ö');
UPDATE wp_links SET link_name = replace(link_name, 'ß', 'ß');
UPDATE wp_links SET link_name = replace(link_name, 'ß', 'ß');
UPDATE wp_links SET link_name = replace(link_name, '°', '°');
UPDATE wp_links SET link_name = replace(link_name, '©', '©');
UPDATE wp_links SET link_name = replace(link_name, '€', '€');
UPDATE wp_posts SET post_content = replace(post_content, 'ä', 'ä');
UPDATE wp_posts SET post_content = replace(post_content, 'Ä', 'Ä');
UPDATE wp_posts SET post_content = replace(post_content, 'ü', 'ü');
UPDATE wp_posts SET post_content = replace(post_content, 'Ãœ', 'Ü');
UPDATE wp_posts SET post_content = replace(post_content, 'ö', 'ö');
UPDATE wp_posts SET post_content = replace(post_content, 'Ö', 'Ö');
UPDATE wp_posts SET post_content = replace(post_content, 'ß', 'ß');
UPDATE wp_posts SET post_content = replace(post_content, 'ß', 'ß');
UPDATE wp_posts SET post_content = replace(post_content, '°', '°');
UPDATE wp_posts SET post_content = replace(post_content, '©', '©');
UPDATE wp_posts SET post_content = replace(post_content, '€', '€');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'ä', 'ä');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'Ä', 'Ä');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'ü', 'ü');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'Ãœ', 'Ü');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'ö', 'ö');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'Ã-', 'Ö');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'ß', 'ß');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, 'ß', 'ß');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, '°', '°');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, '©', '©');
UPDATE wp_posts SET post_excerpt = replace(post_excerpt, '€', '€');
UPDATE wp_posts SET post_title = replace(post_title, 'ä', 'ä');
UPDATE wp_posts SET post_title = replace(post_title, 'Ä', 'Ä');
UPDATE wp_posts SET post_title = replace(post_title, 'ü', 'ü');
UPDATE wp_posts SET post_title = replace(post_title, 'Ãœ', 'Ü');
UPDATE wp_posts SET post_title = replace(post_title, 'ö', 'ö');
UPDATE wp_posts SET post_title = replace(post_title, 'Ö', 'Ö');
UPDATE wp_posts SET post_title = replace(post_title, 'ß', 'ß');
UPDATE wp_posts SET post_title = replace(post_title, 'ß', 'ß');
UPDATE wp_posts SET post_title = replace(post_title, '°', '°');
UPDATE wp_posts SET post_title = replace(post_title, '©', '©');
UPDATE wp_posts SET post_title = replace(post_title, '€', '€');
UPDATE wp_terms SET name = replace(name, 'ä', 'ä');
UPDATE wp_terms SET name = replace(name, 'Ä', 'Ä');
UPDATE wp_terms SET name = replace(name, 'ü', 'ü');
UPDATE wp_terms SET name = replace(name, 'Ãœ', 'Ü');
UPDATE wp_terms SET name = replace(name, 'ö', 'ö');
UPDATE wp_terms SET name = replace(name, 'Ö', 'Ö');
UPDATE wp_terms SET name = replace(name, 'ß', 'ß');
UPDATE wp_terms SET name = replace(name, 'ß', 'ß');
UPDATE wp_terms SET name = replace(name, '°', '°');
UPDATE wp_posts SET name = replace(name, '©', '©');
UPDATE wp_terms SET name = replace(name, '€', '€');
UPDATE wp_term_taxonomy SET description = replace(description, 'ä', 'ä');
UPDATE wp_term_taxonomy SET description = replace(description, 'Ä', 'Ä');
UPDATE wp_term_taxonomy SET description = replace(description, 'ü', 'ü');
UPDATE wp_term_taxonomy SET description = replace(description, 'Ãœ', 'Ü');
UPDATE wp_term_taxonomy SET description = replace(description, 'ö', 'ö');
UPDATE wp_term_taxonomy SET description = replace(description, 'Ö', 'Ö');
UPDATE wp_term_taxonomy SET description = replace(description, 'ß', 'ß');
UPDATE wp_term_taxonomy SET description = replace(description, 'ß', 'ß');
UPDATE wp_term_taxonomy SET description = replace(description, '°', '°');
UPDATE wp_term_taxonomy SET description = replace(description, '©', '©');
UPDATE wp_term_taxonomy SET description = replace(description, '€', '€');
UPDATE wp_tags set tag = replace(description, 'ä', 'ä');
UPDATE wp_tags set tag = replace(description, 'Ä', 'Ä');
UPDATE wp_tags set tag = replace(description, 'ü', 'ü');
UPDATE wp_tags set tag = replace(description, 'Ãœ', 'Ü');
UPDATE wp_tags set tag = replace(description, 'ö', 'ö');
UPDATE wp_tags set tag = replace(description, 'Ö', 'Ö');
UPDATE wp_tags set tag = replace(description, 'ß', 'ß');
UPDATE wp_tags set tag = replace(description, 'ß', 'ß');
UPDATE wp_tags set tag = replace(description, '°', '°');
UPDATE wp_tags set tag = replace(description, '©', '©');
UPDATE wp_tags set tag = replace(description, '€', '€');

Dieser Befehl korrigiert die Umlaute in den Posts, im Post-Titel, in den Kommentaren, in Kategorien, den Tags usw. Es ist aber möglich, das in eurer WordPress Installation danach trotzdem noch weitere fehlerhafte Zeichen in MySQL-Tabellen bestehen. Die könnt Ihr prinzipiell nach dem gleichen Prinzip suchen und ersetzen. Eine umfangreiche Tabelle für die korrekte Zeichenkodierung findet Ihr dazu unter http://bueltge.de/wk-utf-8-konvertierung/130/.

5 Gedanken zu „Fehlerhafte Umlaute in WordPress“

  1. Also latin1 ist es wohl nicht. Dann hab ich überall statt den Zeichen wie oben, Fragezeichen… Kannst du mir sagen, woher ich weiß welchen Charset ich benötige.

    Viele Grüße, Helga

    Antworten
    • Du kannst im phpMyAdmin in der neuen Datenbank nachsehen, welcher Datensatz für die aktuelle Datenbank eingestellt ist (Kollation). Bei neuen Datenbanken ist es häufig $default_charset = ‚utf8mb4‘; oder $default_collation = ‚utf8mb4_general_ci‘;. Im Quellcode bzw. Template deiner WordPress-Seite kannst Du dann nachsehen, welchen Zeichensatz die Seite ursprünglich verwendet. Statt ISO-8859-1 wird es vermutlich utf-8 sein. Dann sollte in der wp-config der Befehl define(‚DB_CHARSET‘, ‚utf8‘); funktionieren.

      Antworten
  2. Danke, tolle Information und Anleitung – hat sehr geholfen und mir riesig viele Probleme weggenommen sowie nach einigen schlaflosen Nächten und hilflosen Versuchen über die Hotlines des Providers Unterstüzung zu bekommen, endlich geholfen!

    Antworten
  3. define(‚DB_CHARSET‘, ‚latin1‘); hinzufügen alleine reicht nicht, es kommt auch darauf an an welcher Stelle, sonst passiert gar nichts.

    Bei mir funktionierte es nur so

    define („WPLANG“, „“);
    define(„ABSPATH“, dirname(__FILE__).“/“);
    define(‚DB_CHARSET‘, ‚latin1‘);
    require_once(ABSPATH.“wp-settings.php“);
    ?>

    Antworten

Schreibe einen Kommentar