尝试将其放入函数中。主题的php。在这种形式下它没有经过测试,但应该可以工作。
/**
* Change the Permalink on save / update
*/
function wpse_297006_rewrite_slug( $post_id, $post, $update ){
// check if it\'s a post
if (!(get_post_type( $post_id ) === \'post\')) return;
// check if it\'s not a revision
if (!(wp_is_post_revision( $post_id ) === false)) return;
// check if it\'s not a revision
$content = get_post_field(\'post_content\', $post_id);
// set the args
$args = [
\'ID\' => $post_id,
\'post_name\' => strtolower( sanitize_title( $content ) ),
];
// unhook this method to prevent infinite loop
remove_action(\'wp_insert_post\', \'wpse_297006_rewrite_slug\');
// apply $args when post is saved
wp_update_post( $args );
// re-hook this method
add_action(\'wp_insert_post\', \'wpse_297006_rewrite_slug\', 10, 3);
};
add_action(\'wp_insert_post\', \'wpse_297006_rewrite_slug\', 10, 3);