I have created a widget that displays some text using a custom font imported with CSS @font-face. The font have support for scandinavian characters åäö, but when I display these characters in my widget it looks like they fallback to another font.

The text is all wrapped in the same element, no individual styling for the special characters.

custom font problem

This problem occurs when I get the text from the widget instance object. If I just echo text with these special characters then there's no issue.

In the widget's update() function I run strip_tags() with the text inputted by a user, then store it in the widget instance.

public function update( $new_instance, $old_instance ) {
    $instance = array();
    $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
    $instance['text'] = ( ! empty( $new_instance['text'] ) ) ? strip_tags( $new_instance['text'] ) : '';
    return $instance;

In widget() where the text is printed it's not manipulated in any way before being printed:

public function widget($args, $instance) {
    echo $args['before_widget'];
    $text = $instance['text'];
    if (!empty( $title)) echo $args['before_title'] . $title . $args['after_title'];
    if (!empty($text)) echo $text;
    echo $args['after_widget'];

How to make text from the widget's field data display properly?

EDIT: Seems like it's an encoding issue. Used asciivalue.com to lookup an ö character that I get from the widget field, and compare it to an ö character that I look up. The result for string "ö ö", with the first one(not working) being from the widget and the second one(working) input directly by me:

ASCII lookup

  • Which font are you using, and exactly how? Most probably the font you are actually importing does not have letters like “ä”. – Jukka K. Korpela Apr 8 '14 at 20:00
  • @JukkaK.Korpela thanks for commenting, but I have stated in the question that the font have support for the characters. The support is there, and it's working well when I just echo the characters. But not working when I get the text through my widget. – Niklas Berglund Apr 8 '14 at 20:01
  • 1
    So you are saying that things work, but they don’t, right? You are not giving any facts or any way to reproduce the problem. – Jukka K. Korpela Apr 8 '14 at 20:05
  • @JukkaK.Korpela I hear you. Edited the question to make it more clear, and added some relevant code from my WP_Widget subclass. – Niklas Berglund Apr 8 '14 at 20:22
  • Live demo might be in order. It does sound like it should work given that it is expected character in text. – Rarst Apr 8 '14 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.