how to remove blog or category word from wordpress URL

how to remove blog or category word from wordpress URL

Many times wordpress developer got requirement to remove the blog or category word from wordpress url. Code for remove blog or category word from wordpress.

how to remove blog or category word from wordpress URL

Many people and wordpress developer want to remove the blog or category wordpress from URL. This is really good for seo also. Many times wordpress developer got requirement to remove the blog or category word from wordpress url.

how to remove blog or category word from wordpress URL
how to remove blog or category word from wordpress URL

In this tutorial I will let you know how can you easily achieve this requirement. There is two-way to achieve this requirement. You can use the .htaccess file for fulfill this requirement.

Note: Apache mod_rewrite rule is must enable to with your Apache web server.

Open your .htaccess file which is present in your root folder of web hosting server. If not then create this file put it.

You can use the permanent redirect rewrite apache rule to achieve this. open your .htaccess file put following lines in that file


RewriteEngine On
RewriteBase /

#This rewrite rule we added for removing the category wordpress from URL
RewriteRule ^category/(.+)$ http://www.purabtech.in/files/$1 [R=301,L]

#This rewrite rule we added for removing the blog word wordpress from URL

RewriteRule ^blog/(.+)$ http://www.purabtech.in/files/$1 [R=301,L]

You can achieve this by changing in the code also. Use the following code do this changes. Open your theme folder and functions.php file and put following code in that file.


function remove_blog_word($without_blog_word_permalink)
{

if(!preg_match("/^\/blog\//",$without_blog_word_permalink))
return $without_blog_word_permalink;

$new_permalink=preg_replace ("/^\/blog\//","/",$without_blog_word_permalink );
return $new_permalink;

}

function remove_category_word($without_category_word_permalink)
 {

 if(!preg_match("/^\/category\//",$without_category_word_permalink))
 return $without_blog_word_permalink;

 $new_permalink=preg_replace  ("/^\/category\//","/",$without_category_word_permalink );
 return $new_permalink;

 }

add_filter("pre_update_option_permalink_structure","remove_blog_word");

add_filter("pre_update_option_permalink_structure","remove_category_word");

Just put above lines in your functions.php file and that will solve your issue.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

3 thoughts on “how to remove blog or category word from wordpress URL”

  1. I tried your solution you posted and I got

    Parse error: syntax error, unexpected '}' in /home/content/n/e/r/nerec/html/wp-content/themes/lifestyle/functions.php on line 75

    I removed your code and it did no good. Now my site is screwed..

Leave a Reply

Your email address will not be published.