WordPress.org

Support

Support » How-To and Troubleshooting » %postname%: removing the dashes

%postname%: removing the dashes

  • Hi,

    Is there a way that i can remove the dashes in my permalink %postname& structure? So that:

    Hello World Test Post

    becomes:

    /helloworldtestpost

    instead of

    /hello-world-test-post

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • hoodamath
    Member

    @hoodamath

    Did you ever figure this out? I would love to know how to do this!!!

    PBP_Editor
    Member

    @pbp_editor

    Save this code as a php file – I called it compact-slug.php – and drop into the plugin folder

    <?php
    /*
    Plugin Name: Compact Slug
    Description: This plugin adds a function that condenses spaces in a slug instead of replacing them with a dash.
    Version: 1.0
    Author: Shaun Flagg
    License: GPL2
    */
    
    function generateSlug($slug)
    {
    $slug = strtolower($slug);
    
    $slug = preg_replace('/&.+?;/', '', $slug); // kill entities
    $slug = str_replace('.', '-', $slug);
    $slug = preg_replace('/[^%a-z0-9_-]/', '', $slug);
    $slug = preg_replace('/\s/', '', $slug);
    $slug = preg_replace('|-+|', '-', $slug);
    $slug = trim($slug, '-');
    
    return $slug;
    }
    remove_filter('sanitize_title', 'sanitize_title_with_dashes');
    add_filter('sanitize_title','generateSlug');
    
    ?>
    }
    Shane G.
    Member

    @shane-g-1

    Hi,

    Reset your desired permalink from wordpress admin area and add this code in htaccess:

    # BEGIN WordPress
    
    <IfModule mod_rewrite.c>
    ErrorDocument 404 /index.php?error=404
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    Now, check with blog posts and pages.

    Thanks,

    Shane G.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘%postname%: removing the dashes’ is closed to new replies.