WordPress.org

Ready to get started?Download WordPress

Forums

%postname%: removing the dashes (4 posts)

  1. Joeynoh
    Member
    Posted 4 years ago #

    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!

  2. hoodamath
    Member
    Posted 4 years ago #

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

  3. PBP_Editor
    Member
    Posted 4 years ago #

    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');
    
    ?>
    }
  4. Shane G.
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic