• I’d like to trim my post_name to 16 characters to shorten my URLs. I’m wondering if I should go into phpMyAdmin and change varchar(200) to varchar(16) for post_name. If I go from varchar(200) to varchar(16), will I just be deleting the data after character 16 and holding onto the first 16 characters? (That’s what I’m hoping.)
    Since post_name is generated from post_title in wordpress, and the post_title is often going to be longer than 16 characters, will this cause some kind of error in WP when a title is longer than 16 characters? or will the database store the first 16 characters it is sent and disregard the rest (that’s what I’m hoping.) BTW, the post_name will always be generated from post_title in my blog because the slug field will be left blank. Meanwhile, I have a lot of imported posts that don’t have a slug. (In the logic of post.php, it looks like it first tries to get the post_name from the slug field, and then if there is no data for the slug, it sanitizes the post_title instead.)
    I’m sure there are other ways to trim the post_name with PHP, but I’m concerned about what the impact will be if I start messing with the PHP. So I’m wondering if limiting the string length with phpMyAdmin is the simplest way to proceed.

Viewing 1 replies (of 1 total)
  • Thread Starter emsdc

    (@emsdc)

    ok, for posterity, it looks like I have what I need. I found this in functions-formatting.php…
    function sanitize_title($title) {
    $title = do_action(‘sanitize_title’, $title);
    return $title;
    …and added substr function to make this…
    function sanitize_title($title) {
    $title = do_action(‘sanitize_title’, $title);
    $title = substr($title,’0′,’16’);
    return $title;
    Simple enough. Hopefully that won’t affect anything else negatively. Now I’ll just have do something in phpMyAdmin to trim my old post_names. Something like in this post: https://mjtsai.com/blog/2004/05/20/wordpress/

Viewing 1 replies (of 1 total)
  • The topic ‘trim the post_name in phpMyAdmin?’ is closed to new replies.