WordPress remove_accents() not working when getting value from XML

I have special problem. I’m using WP All Import Pro plugin to import XML to WordPress posts.

I need use WordPress function remove_accents() for strip Czech accents (ěščřžýáíé) for post slug.

Read More

If I set variable manually (ignore $mytitle), all works fine.

function seofriendly_slug($mytitle) {
    $finalslug = remove_accents("Test string ěščřžýáíé");
    return $finalslug;
}

OUTPUT: Test string escrzyaie

But if I use variable $mytitle that coming from XML (utf8):

[seofriendly_slug({PRACOVISTE[1]/@nazev})]

Variable is set propertly but remove_accents does not work:

function seofriendly_slug($mytitle) {
    $finalslug = remove_accents($mytitle);
    return $finalslug;
}

OUTPUT: Test string ěščřžýáíé

Last info: When I use mb_detect_encoding($mytitle), output is “ASCII” but in XML header is UTF-8.

Related posts

1 comment

  1. I get solution from WorkScout theme creator – PureThemes.

    html_entity_decode($prepareslug, ENT_QUOTES, 'UTF-8');
    

    Final code:

    function seofriendly_slug($nazev,$doplnek,$obec) {
        if ($doplnek ==NULL) { $titulek = $nazev; } 
            else { $titulek = $doplnek; }
        $prepareslug = $titulek."-".$obec;
        $prepareslug = html_entity_decode($prepareslug, ENT_QUOTES, 'UTF-8');
        $finalslug = sanitize_title($prepareslug);
        return $finalslug;
    }
    

Comments are closed.