正如@Jacob所提到的,是一个在许多上下文中使用的通用实用函数,因此,您可能希望使用其他方法,或者有选择地通过其他钩子钩住它$post
对象(例如。edit_post
或以其他方式定义所编辑的帖子是否为页面类型。
大致如下:
<?php
// sanitizing function.
function wpse341230_remove_false_words($slug) {
if (!is_admin()) return $slug;
$keys_false = array(\'a\',\'and\',\'above\',\'the\',\'also\');
$slug = explode (\'-\', $slug);
$slug = array_diff($slug,$keys_false);
return implode (\'-\', $slug);
}
// array of post types where sanitizing function should be hooked;
$types = array(
\'page\',
\'product\',
);
// hook the following function a hook with $post object. e.g. edit_post or save_post.
add_action(\'edit_post\',\'wpse341230_hook_sanitize_title\', 10, 2);
// this function checks if the post type is one we want to sanitize the title.
function wpse341230_hook_sanitize_title($post_ID, $post, $types){
// if the $post->post_type property is in the array of types for sanitizing, hook the sanitizing function
if( in_array($post->post_type, $types) ){
add_filter(\'sanitize_title\',\'wpse341230_remove_false_words\');
}
}
?>
我建议在的管理页面请求部分检查操作中运行的可用挂钩
this documentation page 检查通常可用的挂钩。