WordPress: update slug on post rename

When you create a new post in wordpress, the “permalink” a.k.a slug, is automatically filled out for you. However, if you edit the title of your page, it does not get automatically updated. Here is an untested piece of code you can try to make it automatically update your slug whenever you change the title in wordpress.


add_action('admin_footer', 'slug_it');
function slug_it() {
echo "<script type="'text/javascript'">
jQuery(document).ready(function($){ $('#title').blur( function() { $('#edit-slug-box').html(''); autosave(); } ); });
</script>";
};

put this in your theme’s functions.php

Note: People say that this is not a good idea, and maybe the reason why it’s not in wordpress core, is because you don’t want the permalink to change and mess up your SERP / SEO. However, I find this very useful when I am in the middle of writing a new post and need to change the title.