Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
FV Top Level Categories
// 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