How to replace %20 with -. (Wordpress)
So what i need: link like ://www.yyy.xx/tag/55 5/
should change in ://www.yyy.xx/tag/55-5/
instead of: http://www.yyy.xx/tag/55%205/
Try using str_replace for that.
like for example.
$url = "http://www.yyy.xx/tag/55%205/";
$url = str_replace('%20', '-', $url);
You can try something like this. That filter changes your URL. I wrote it here so I don't test it if doesn't work try to experiment to fetch tag.
function custom_link($link, $term, $taxonomy) {
if ( is_tag() ) {
return $link;
}
return str_replace('%20', '-', $link);
}
add_filter('tag_link', 'custom_link', 10, 3);
or
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
function custom_link() {
if (strpos($url,'%20') == true) {
return str_replace('%20', '-', $url);
}
add_filter('tag_link', 'custom_link', 10, 3);