Uncategorized

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:
http://cogdogblog.com/hacks/make-slugs.php.zip

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

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff 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. And he is 100% into the Fediverse (or tells himself so) Tooting as @cogdog@cosocial.ca