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 diesem Fall hier war das Problem, das die vorhandene Datenbank im Zeichensatz latin1_swedish_ci kodiert war. In der neuen Mysql 5 Datenbank wurde aber utf8 verwendet. Das Problem gibt es häufig bei älteren WordPress-Versionen vor 2.9. Inzwischen ist die Standard-Kodierung bei neuen WordPress-Installationen UTF-8.

Die einfache Lösung über wp-config.php

Am einfachsten ist es hier die Datei wp-config.php im WordPress-Hauptverzeichnis zu öffnen (bitte vorher eine Sicherung der Datei anlegen!) und folgendes einfügen:

define('DB_CHARSET', 'latin1');

Es kann sein, das sich in der Datei schon eine bestehende Zeile für den DB-CHARSET befindet, die kommentiert man einfach so aus (durch die // Striche vorne weg):

// define(‘DB_CHARSET’, ‘utf8′);

Fertig!

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 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/.

3 Kommentare
  1. Nöthiger sagte:

    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

Einen Kommentar hinterlassen


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.