WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Regenerate all slugs from post title? (7 posts)

  1. gunnerstown
    Member
    Posted 6 months ago #

    I just migrated from Squarespace to WordPress and all of my post slugs (>1500 of them) are incorrect. They have a 7-digit number (date) added to the front of them:

    this-is-the-desired-slug has become 2013524this-is-the-desired-slug

    I have searched high and low for the easiest way to correct this. I was hoping that there would be a plugin that would regenerate all slugs using the Post Title, but can't seem to find one! :(

    I'd like to retain the old site structure so that when I point my domain from the old host to the new one, all the links work.

    Any suggestions? Thanks.

  2. keesiemeijer
    moderator
    Posted 6 months ago #

  3. gunnerstown
    Member
    Posted 6 months ago #

    Thanks for your reply. I saw that suggestion already, but from the looks of it, it will sanitize the slug, which I don't want to do, since it will strip the "the" and "a" etc. from the slug...

    Any other suggestions?

  4. keesiemeijer
    moderator
    Posted 6 months ago #

    http://codex.wordpress.org/Function_Reference/sanitize_title

    Despite the name of this function, the returned value is intended to be suitable for use in a URL, not as a human-readable title. It will not strip words or letters from the title. It does replace special accented characters.

    if I do this:

    <?php echo sanitize_title('will it strip the and a from a slug'); ?>

    It prints:

    will-it-strip-the-and-a-from-a-slug
  5. gunnerstown
    Member
    Posted 6 months ago #

    OK... Thanks.

    Now a really stupid newbie question - how exactly do I run that function? :-P

    I know it has something to do with function.php...

    Thanks.

  6. gunnerstown
    Member
    Posted 6 months ago #

    And is there anything i would have to change in that code you sent me? Or will it automatically go through every post and replace the slug with the post title?

    Just checking that there isn't anything custom in the code.

    Appreciate your help very much! :)

  7. gunnerstown
    Member
    Posted 6 months ago #

    Thanks keesiemeijer - it seems to have worked. You've saved me hours of work! :)

Reply

You must log in to post.

About this Topic