WordPress.org

Ready to get started?Download WordPress

Forums

dashes to underscores perm (2 posts)

  1. hauntingreview
    Member
    Posted 2 years ago #

    Hey guys,
    As a few topics here already cover, I'm trying to find a better way to convert my underscores to dashes more permanently within the WP system.

    While:
    add_filter( 'sanitize_title', 'dashes_to_underscore' );
    function dashes_to_underscore( $title ){
    return str_replace( '-', '_', $title );
    }

    Has worked for me, I noticed that none of my sidebars worked.

    I was more-so wondering if you guys had a better solution (as my team and I publish several entries a day on a few blogs and update the permalink manually is a bit of a hassle when you have long titles.

    I rewrote the code a bit to:
    add_filter( 'sanitize_file_name', 'dashes_to_underscore' );
    function dashes_to_underscore( $title ){
    return str_replace( '-', '_', $title );
    }

    and was wondering if you guys forsee any issue with this OR if you know how to make it work at all without affecting anything but my post titles.

    Thanks

  2. Francisco Aguirre
    Member
    Posted 2 years ago #

    Hi hauntingreview,

    I'm looking for the very same thing! So far I've used this function, but it also makes my widgets to stop showing :(

    /** Dashes to underscores */
     add_filter( 'sanitize_title', 'dashes_to_underscore' );
     function dashes_to_underscore( $raw_title ){
       return str_replace( '-', '_', $raw_title );
     }

    Nothing is really bad, but after publishing, I have to comment it to have my blog display everything as expected :(

    I've tried 4 (!) different themes + frameworks and all have the same problem, but in different areas.

    And so, I have this question... How can I modify this function to tell WP to only change a post's slug to underscores?

    As in other threads, I switched from MT where underscores were standard, and so now my pages have decent PR and are indexed that way!

Topic Closed

This topic has been closed to new replies.

About this Topic