您可以使用sanitize_title()
功能:
$string = "This is title string";
// return "this-is-title-string"
$slug = sanitize_title( $string );
您还可以过滤
sanitize_title()
函数使用
sanitize_title
filter:
add_filter( \'sanitize_title\' , \'sanitize_filter_callback\', 10, 3 );
function sanitize_filter_callback( $title, $raw_title, $context ) {
// do something
}