• Hi,

    I’m currently working with Facebook’s Graph API and have noticed that the API returns an error if there is a number (1,3,5, etc.) on the permalink a.k.a URL. I tried to find a way to remove the numbers from the permalink with a function but couldn’t do so.

    Is there any function that’d remove the numbers from a permalink?

    Please help.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m assuming you want to remove numbers as a possibility from all post slugs when the post is created. Doing so for the automatic assignment that happens soon after the title is entered is tricky, but simply stripping out numbers when the post is saved is straight forward enough. Hook the ‘save_post’ action.

    You do need to verify the resulting slug is not duplicated anywhere and since numbers are not available, assign additional letters to differentiate otherwise identical slugs:

    common-slug
    common-slug-a
    common-slug-b
    common-slug-c etc.

    is there any easy way of doing it for the auto assignment?

    Moderator bcworkz

    (@bcworkz)

    Alexander, I’m glad you asked!

    When I said it was tricky, I was going on memory from the last time this came up. I recall tracing through a bunch of javascript code to find the ajax call and being unable to find corresponding ajax handler in PHP. Since I couldn’t find it, I deemed it “tricky”.

    I decided to give it another go. I still had trouble finding the handler, but this time I accidentally stumbled upon some code that was crucial to finding the handler. The rest was easy to trace.

    So now knowing the correct filter, this is actually easier than using ‘save_post’. Use the ‘wp_unique_post_slug’ filter to strip out numbers.(Or otherwise modify as desired) Naturally you still need to ensure the modified slug does not occur already.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Remove numbers from permalink?’ is closed to new replies.