skip to Main Content

Can anyone point me to the standard code WordPress uses to turn a blog post url from this:

http://myblog.com/?p=123

into this:

http://myblog.com/this-is-my-articles-title-i-think

If the post title was: This Is My Article’s “Title” (I Think)

2

Answers


  1. WordPress doesn’t redirect or rewrite requests. index.php serves the content based on the original request URI. It catches requests that don’t exist and figures them out from the plug. This code is in the WordPress document root in .htaccess.

    <IfModule mod_rewrite.c>  
    RewriteEngine On  
    RewriteBase /wordpress/  
    RewriteRule ^index.php$ - [L]  
    RewriteCond %{REQUEST_FILENAME} !-f  
    RewriteCond %{REQUEST_FILENAME} !-d  
    RewriteRule . /wordpress/index.php [L]  
    </IfModule>
    

    If you want to know how WP generates the permalink slugs, look in wp-includes/formatting.php for this function:

    function sanitize_title_with_dashes($title) { ... }
    
    Login or Signup to reply.
  2. In your wordpress admin go to settings > permalinks and select ‘post name’ then save changes and you’re all set.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search