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.
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.
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..
Tried the .htaccess rewrite rules.
It is working but no content can be found now.
Do both bits of code need implementing together?
Remember that the new WordPress 3.1 has changed the file that needs editing. Here’s a post that explains the new process: http://www.nelsonpires.com/wordpress/remove-word-category-from-wordpress-urls/