Remove Extra Classes from Post Title

Try this.

// **** Remove unwanted classes
function remove_classes($classes, $class, $post_id)
{
    // Array that holds the undesired classes
    $removeClasses = array(
        'category-',
        'tag-'
    );

    // Array to store the new class names
    $newClasses = array();
    foreach ($classes as $_class)
    {
        // Iterate through the array of undesired classes and
        // check if the current $_class name starts with the
        // undesired class name
        $hasClass = FALSE;
        foreach ($removeClasses as $_removeClass)
        {
            if (strpos($_class, $_removeClass) === 0)
            {
                $hasClass = TRUE;
                break;
            }
        }

        // If $_class does not contain an undesired class name,
        // add it to the array of new class names.
        if (!$hasClass)
        {
            $newClasses[] = $_class;
        }
    }

    // Return the array of new class names
    return ($newClasses);
}
add_filter('post_class', 'remove_classes', 10, 3);

This filter declares an array of undesired class names ($removeClasses). Expand it with the class names you don’t want to have.

Then, the function iterates through the passed array of classes ($classes) and checks if it contains classes you have defined in the $removeClasses array. If not, it will add it to a new array ($newClasses). If yes, it will skip it.

Finally it returns the new array $newClasses.

Basically it sorts out the classes you don’t want. And instead of manipulating the passed $classes array, it creates a new one with only the good classes and returns that instead.

I haven’t tested it though. I don’t have a WordPress installation available here right now to fiddle around with. It could be that it doesn’t work, because post_class might not be the right filter.