🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

Remove the 'category' URL from WordPress category permalinks

I wonder if you have noticed that the category URLs of Naibabiji do not contain 'category'. For example, https://blog.naibabiji.com/tutorial looks shorter than the default URL. Your category URLs probably contain 'category'. How to remove 'category' from the category URL? There are three methods:

Method 1: Use . as the category prefix

分类目录前缀In the WordPress Admin Dashboard, set the category prefix to . (English period), then save.

Method 2: Add code to the Theme file

Copy the code below and paste it into your theme's functions.php file, then save. This method is from the blog '我爱水煮鱼'.
add_filter('request', function($query_vars) {
	if(!isset($_GET['page_id']) && !isset($_GET['pagename']) && !empty($query_vars['pagename'])){
		$pagename	= $query_vars['pagename'];
		$categories	= get_categories(['hide_empty'=>false]);
		$categories	= wp_list_pluck($categories, 'slug');

		if(in_array($pagename, $categories)){
			$query_vars['category_name']	= $query_vars['pagename'];
			unset($query_vars['pagename']);
		}
	}

	return $query_vars;
});

add_filter('pre_term_link', function($term_link, $term){
	if($term->taxonomy == 'category'){
		return '%category%';
	}

	return $term_link;
}, 10, 2);

Method 3: Use a Plugin

If you have installedWPJAM Basicthis plugin, then this feature is built-in. If you dislike WPJAM Basic, you can installNo Category Basethis plugin, which also supports removing the 'category' URL in multisite mode.Download LinkThe 'Remove Category URL' plugin can also remove the 'category' link. https://wordpress.org/plugins/remove-category-url/

Which method is better?

Obviously, Method 1 is the most convenient. Naiba has tested all three methods; there's no significant difference. Although in the sitemap, they all appear ashttps://blog.naibabiji.com/./vps-you-huithis form with a './', it does not affect Baidu or Google indexing, nor does it affect the normal display on the website. It only appears inSitemap.

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step instead.

「Naibabiji WordPress Website Building Coaching」 — From selecting a domain and purchasing hosting to installing themes and publishing posts, I「ll guide you through every step, helping you avoid detours and reach your goals directly.

👉 Learn about Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan to Follow