Using underscores instead of hyphens in the permalink

IMO hooking into sanitize_title is probably the best way to go here. Check out this plugin by Mark Jaquith which does something similar: http://txfx.net/files/wordpress/periods-in-titles.phps

As for updating the old posts, I would just write a simple script that would generate sql to manually update everything. (code not tested)

<?php
function sanitize_title_with_underscores( $title ) {
    return str_replace( '-', '_', sanitize_title_with_dashes( $title ) );
}

$posts = get_posts( array( 'numberposts' => -1 ) );

foreach ( $posts as $post ) {
    global $wpdb;
    $id = absint( $post->ID );
    $name = sanitize_title_with_underscores( $post->post_name );
    print "\n" . "UPDATE $wpdb->posts SET post_name="{$name}" WHERE ID = {$id};"
}
?>

Probably not the most elegant solution, but for something that only needs to be done once, it should work rather well.

Leave a Comment