Force WordPress to Show Pages Instead of Category

One possible solution is to not change the category base and leave as-is, but instead modify any output of a category link to strip the category base via a filter. This of course will result in a 404 if you haven’t created a page in place of where these links point, so creating a page for every category is required.

function wpa_alter_cat_links( $termlink, $term, $taxonomy ){
    if( 'category' != $taxonomy ) return $termlink;

    return str_replace( '/category', '', $termlink );
}
add_filter( 'term_link', 'wpa_alter_cat_links', 10, 3 );

You’ll probably want to test this thoroughly for any side-effects, use at your own risk!

EDIT – altering just top level category links:

function wpa_alter_cat_links( $termlink, $term, $taxonomy ){
    if( 'category' == $taxonomy && 0 == $term->parent ){
        return str_replace( '/category', '', $termlink );
    }
    return $termlink;
}
add_filter( 'term_link', 'wpa_alter_cat_links', 10, 3 );

Leave a Comment