如何在WordPress中自动将固定链接从000-111-222更改为000111222

时间:2014-10-14 04:21:01

标签: wordpress .htaccess

我想将永久链接mydomain.com/000-111-222更改为WordPress中的mydomain.com/000111222

请建议,编辑WordPress代码或.htaccess

之间的偏好

1 个答案:

答案 0 :(得分:1)

请将代码添加到主题functions.php中。它将解决问题。

function generateSlug($slug)
{
$slug = strtolower($slug);
$slug = preg_replace('/&.+?;/', '', $slug); // kill entities
$slug = str_replace('.', '-', $slug);
$slug = preg_replace('/[^%a-z0-9_-]/', '', $slug);
$slug = preg_replace('/\s/', '', $slug);
$slug = preg_replace('|-+|', '-', $slug);
$slug = trim($slug, '-');
return $slug;
}
remove_filter('sanitize_title', 'sanitize_title_with_dashes');
add_filter('sanitize_title','generateSlug');