Skip to content

Instantly share code, notes, and snippets.

@scribu
Created July 9, 2012 23:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scribu/52b8db30e27ac0b9deef to your computer and use it in GitHub Desktop.
Save scribu/52b8db30e27ac0b9deef to your computer and use it in GitHub Desktop.
FV Top Level Categories
<?php
// Add to bottom of top-level-cats.php
add_filter('category_link', 'top_level_cats_remove_cat_base');
function top_level_cats_remove_cat_base($link) {
$category_base = get_option('category_base');
// WP uses "category/" as the default
if ($category_base == '')
$category_base = 'category';
// Remove initial slash, if there is one (we remove the trailing slash in the regex replacement and don't want to end up short a slash)
if (substr($category_base, 0, 1) == '/')
$category_base = substr($category_base, 1);
$category_base .= '/';
return preg_replace('|' . $category_base . '|', '', $link, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment