Remove The Category Base From WordPress

I am setting wordpress 2.8.4 for my client. Actually I don’t want CATEGORY base like(www.mysite.com/category/something/) in my new site as SEO issue. So, I want to remove category from wordpress categories. I want my address to be like this(www.mysite.com/something/). I search lot on internet and finally I come up with this final trick, which is easy to do and don’t need any plugin . This is simply a twik in wordpress admin file. This twik work with Next page issue as well like (www.mysite.com/something/page/2/). You just need to add some line of code in admin file.

Here is what I did and I’ve fooled around with mine enough to where I think it works right. First some caveats:

1)  I didn’t change any code inside the theme so this shouldn’t matter.

2) I don’t use subcategories so I don’t know if that works or not.

3) My permalink structure is set at /%category%/%postname%/ – if yours is different, you’ll probably need to tweak it, or it may work for you as well.

4) This isn’t a plugin (yet, I might get around to doing that but I have never written a plugin before and I wanted to get this out now). This means when you upgrade WordPress, you have to insert the code again.

So, here is the solution.

1) In wp-includes/category-template.php search for the following line of code:

$catlink = get_option('home') . user_trailingslashit($catlink, 'category');

Just below that, insert the following:

$catlink = str_replace('/category', "", $catlink);

2) In wp-includes/classes.php search for the following block of code:

if ( isset($error) )
$this->query_vars['error'] = $error;

Just below that, insert the following:

if (@$this->query_vars["name"] == "page")
{
$tmp_ar = $this->query_vars;
$this->query_vars = array();
$this->query_vars["paged"] = str_replace("/", "", $tmp_ar["page"]);
$this->query_vars["category_name"] = $tmp_ar["category_name"];
}

3) Finally, in your .htacces file, add the following to redirect your old /category/ URLs to your new ones (if your blog doesn’t reside in the root, you’ll have to tweak it):

RewriteRule ^category/(.+)$ http://www.domain.com/$1 [R=301,L]

If you do same as here, then I’m sure you will rock.

I have tried this on latest wordpress 2.8.4
Now back to setting up your nice blog 🙂

Ashesh

सयौ थुङ्गा फूलका हामी एउटै माला नेपाली, Welcome to my webpage. I'm from the Himalayan Country of Nepal. Well talking about me, I like mostly Web programming and Designing and furthermore I like Philosophical literature, Photography, Social networking. And I am Romantic and Sentimental person to some extent. Read more...

View Comments