Skip to content
Advertisement

Need script to not run if user is logged in

Goal: To hide specific categories from showing in the post meta area

The below code achieves that (which is in the theme’s functions.php file):

function exclude_these_categories($thelist, $separator=' ') {
        //Exclude the following categories
        $exclude = array('Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5', 'Category 6');
        $cats = explode($separator, $thelist);
        $newlist = array();
        foreach($cats as $cat) {
            $catname = trim(strip_tags($cat));
            if(!in_array($catname, $exclude))
                $newlist[] = $cat;
        }
        return implode($separator, $newlist);

}
add_filter('the_category','exclude_these_categories', 10, 2);

However, it then hides all categories when editing, not just the specific categories mentioned above: missing categories screenshot

I need a solution so that the above code won’t run if someone is logged in; or add to the code so that the categories show up while editing.

Advertisement

Answer

I think u should run the filter only if it’s not on admin page:

if(!is_admin())
{
   add_filter('the_category','exclude_these_categories', 10, 2);
}
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement