所以,这就是我最终得到的结果,在转换导入内容的片段后,这被连接到sanitize\\u链接中。最后2条规则是为了保持与所使用的可移动类型permalink方案的兼容性(它处理的不仅仅是连字符)
我相信这不是最有效的,但它可能会帮助别人。
function convert_permalinks( $old_slug ){
global $post;
if (!get_post_type() == "post") {
return $old_slug;
}
# replace hyphens with underscores
# replace apostrophes with spaces
#if last char is an underscore, remove it.
$search_values = array("-", "–","‘","\'","’","“","”");
$replace_values = array("_","");
// if there are no hyphens then skip
if (! preg_match(\'/-/\',$old_slug))
return $old_slug;
$new_slug = str_replace( $search_values, $replace_values, urldecode($old_slug));
if (strlen($new_slug) > 30)
$new_slug = trim(substr($new_slug,0,30));
if ($new_slug[strlen($new_slug)-1] == "_")
$new_slug = substr($old_slug,0,strlen($new_slug)-1);
return $new_slug;
}