My First WP Hack

I just wrote a itty bitty PHP script to deal with my 800+ imported MovableType posts- as far as my newbie eyes could see, the Permalink URLs contstructed from these were producing some 3 mile URLs because the format I used based on the post name.

On new WP entries, I have options to create a “slu”, a shorter URL name used for Permalinks. The task was to walk the database and re-write the values for postnamein the posts table to a shorter string. The script merely reads in the current postname (basically the title all converetd to lower caase with “-” replacing spaces” from the table, split it into a pHP array based on the hyphen, and if there were more than 2 “chunks, e.g. “my-really-big-long-winded-blog-post-makes-a-long-url”, it updates the row in the database with just the first two pieces.

It’s not the greatest approach, but our domain is long enough already, I hate having even longer URLs for Permalinks. You can find the the PHP script at:

Just ftp make-slugs.php to your wp-admin directory, and call it from the browser

If this kind of stuff has any value, please support me monthly on Patreon or a one time PayPal kibble toss
Profile Picture for Alan Levine aka CogDog
An early 90s builder of the web and blogging Alan Levine barks at CogDogBlog.com on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person.