• Hi all,

    By default categories are accessed via example.com/category/here

    I would like to be able to access categories without the dir category, eg example.com/here where ‘here’ is a category.

    I have tried adding ‘/’ to ‘Category base’ in Options>Permalinks, but this doesnt seem to work.

    It seems I can change the name of category eg example.com/tags/here but not remove it altogether.

    Any suggestions appreciated

    🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • No suggestion. You cannot remove it. WP needs “something” there.

    Thread Starter pentascape

    (@pentascape)

    gah.
    thanks though 🙂

    I dunno, I’ve had luck getting rid of it. The way I got around is:

    1) open the file “category-template” in the “wp-includes” directory

    2) around line 41, between add "$catlink = str_replace('category/', '', $catlink);"

    3) the function should end up looking like this:

    function get_category_link($category_id) {
    	global $wp_rewrite;
    	$catlink = $wp_rewrite->get_category_permastruct();
    
    	if ( empty($catlink) ) {
    		$file = get_option('home') . '/';
    		$catlink = $file . '?cat=' . $category_id;
    	} else {
    		$category = &get_category($category_id);
    		$category_nicename = $category->category_nicename;
    
    		if ( $parent = $category->category_parent )
    			$category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename . '/';
    
    		$catlink = str_replace('%category%', $category_nicename, $catlink);
    		$catlink = get_option('home') . trailingslashit($catlink);
    
    		//remove the uneeded name in link
    		$catlink = str_replace('category/', '', $catlink);
    	}
    	return apply_filters('category_link', $catlink, $category_id);
    }

    This removes the string “category” from category links, which seems to be unneeded. You can try it out by going to a category page before you make the change and remove the “category” from the URL, it seems to still work. This just makes it so that it isn’t included in the links generated by WordPress.

    If you want me to go into why this works and how regular expressions/mod_rewrite is setup on WordPress I can try, but I’ll just leave this bit of info for now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘mod_rewrite removing category dir’ is closed to new replies.