
[ad_1]
wordpress developers add /category/urls to easily identify sites with /tag/, however if you find your category url ugly and want remove category in WordPress URL to make your website more professional and easier to SEO, you can always do this. Currently, there are many ways to remove categories in WordPress URLs, most of the ways I introduce are done quickly and without causing errors for the wp page. Please refer to the article of WordPress tips Please
Instructions on how to remove categories from WordPress URLs
There are 4 ways to remove /category/ from category URL, you can choose the most convenient way to do it.
To note: If you are creating a new website, that is completely normal, no problem. But if you are going to do this for a site indexed by Google, you must set the redirect correctly so as not to affect SEO.
Remove /category/ in URLs with Yoast SEO plugin
This way we will use the plugin to remove the category fragment in the link. This is the easiest way to delete a category because the plugin I’m promoting below is an absolute must for any WordPress site if you want good SEO. The plugin I am talking about is the SEO by Yoast plugin, which can be called Yoast SEO or WordPress SEO. After installing the SEO by Yoast plugin, point to the SEO menu -> Search Appearance -> Taxonomies. Next, scroll down to find the Category URL section and move the button to the Remove section as shown below:
Remove Category in WordPress URL with Rank Math SEO Plugin
Rank Math SEO plugin is gradually being used more and more by many attractive features. If you are using the Rank Math plugin without using Yoast SEO, follow the instructions below to remove /category/ from the URL.
Go to the Rank Math menu -> General Settings -> Links. In the Strip Category Base section, toggle On to remove /category/.
Remove /category/ with Remove Category URL plugin
If Rank Math plugin or Yoast SEO plugin is not installed on the site you are using, you can install Remove Category URL plugin. Just install the Remove Category URLs plugin on your website and you don’t have to do anything else. The advantage of this plugin is that it automatically removes the “category” in the URL and sets up an automatic redirect from the old URL to the new URL.
If you don’t know how to set up a canonical redirect, you can follow these 3 methods because the plugin will automatically redirect the old URL.
Remove /category/ in URL with .htaccess file
This method is faster but I still recommend using the above methods. To delete a category, add the following line of code to the domain .htaccess
Rewrite rule ^category/(.+)$ http://domain.com/$1 [R=301,L]
Note: Before doing this, you should backup your .htaccess file to avoid confusion, and remember to replace domain.com with your site link in the code above.
When you use one of the links in your link will be the following: hocwordpress.vn/thu-thuat-wordpress so you have successfully removed the category in the wordpress url.
How to remove /category/ and parent category slug from WordPress URL
As mentioned above, you should be able to remove /category/ from the category URL. However, if you want to simplify category association by removing parent category slugs, follow the instructions below.
Note: Do not shorten the URL too much, it will be easy to duplicate. In fact, the way below I guide you more, I do not encourage you to do it.
Suppose your website initially has category paths like: hocwordpress.vn/category/wordpress hocwordpress.vn/category/wordpress/thu-thuat-wordpress
After applying the instructions below, the URL will be just short. is: hocwordpress.vn/wordpress hocwordpress.vn/thu-thuat-wordpress
Here’s how:
Copy the code below and paste it at the end of the functions.php file in the theme you are using. Then go to Settings -> Static Path and select Save.
// Remove Parent Category from Child Category URL add_filter('term_link', 'devvn_no_category_parents', 1000, 3); function devvn_no_category_parents($url, $term, $taxonomy) { if($taxonomy == 'category'){ $term_nicename = $term->slug; $url = trailingslashit(get_option( 'home' )) . user_trailingslashit( $term_nicename, 'category' ); } return $url; } // Rewrite url mới function devvn_no_category_parents_rewrite_rules($flash = false) { $terms = get_terms( array( 'taxonomy' => 'category', 'post_type' => 'post', 'hide_empty' => false, )); if($terms && !is_wp_error($terms)){ foreach ($terms as $term){ $term_slug = $term->slug; add_rewrite_rule($term_slug.'/?$', 'index.php?category_name=".$term_slug,"top'); add_rewrite_rule($term_slug.'/page/([0-9]{1,})/?$', 'index.php?category_name=".$term_slug."&paged=$matches[1]','top'); add_rewrite_rule($term_slug.'/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=".$term_slug."&feed=$matches[1]','top'); } } if ($flash == true) flush_rewrite_rules(false); } add_action('init', 'devvn_no_category_parents_rewrite_rules'); /*Sửa lỗi khi tạo mới category bị 404*/ function devvn_new_category_edit_success() { devvn_no_category_parents_rewrite_rules(true); } add_action('created_category','devvn_new_category_edit_success'); add_action('edited_category','devvn_new_category_edit_success'); add_action('delete_category','devvn_new_category_edit_success');
So together we discovered how remove category in WordPress URL. Please leave your comment for WordPress tips If you don’t know how to do it, see you in the next articles
[ad_2]