How to Remove Specific Categories from get_category in WordPress

On a recent WordPress website project I was working on, I needed to remove specific categories from the list of categories that the “get_category()” function returns. Carl Bliss discovered the solution on the Technokinetics blog.

First, add the following to functions.php:

cat_name != 'CATEGORY TO EXCLUDE' && $category->cat_name != 'ANOTHER CATEGORY TO EXCLUDE') {
	  if ($first_time == 1) {
		echo 'name ) . '" ' . '>'  . $category->name.'';
		$first_time = 0;
	  } else {
		echo $separator . 'name ) . '" ' . '>' . $category->name.'';
	  }
	}
  }
}
?>

Make sure to replace the “CATEGORY TO EXCLUDE” text with your category’s nicename.

Then add the following to your theme:


That’s it!

Posted in ,

The Mighty Mo! Design Co.

1 Comment

  1. jogol on June 5, 2011 at 6:26 pm

    //exclude categories with id 1 and 3
    $args = array(‘exclude’ => array(1,3));
    $categories = get_categories( $args );



RSS From Toby’s Blog

  • Fortify Your WordPress Site: Essential Security Steps
    Securing your WordPress site is a critical component of maintaining your online presence and safeguarding your data. Security is no longer a luxury, it has become a necessity in today’s digital world, where threats are lurking at every corner. This piece dives deep into WordPress security basics, giving you a comprehensive understanding of common vulnerabilities…
  • Master Your Site: Customizing WordPress Themes
    Just as a house is more than bricks and mortar, a WordPress site is much more than simple code. It’s a cohesive structure built with various layers such as PHP, HTML, CSS, and other key elements. Customizing WordPress themes involves gaining an in-depth understanding of this structure, learning to inspect and adjust design elements with…
  • Mastering WordPress Basics for Beginners within Hours
    Welcome to the world of WordPress, a widely used Content Management System (CMS) that powers millions of websites worldwide. Being immensely flexible and user-friendly, WordPress offers an endless scope to create, manage, and customize your website according to your needs and preferences. In this segment, we attempt to introduce you to the basics of WordPress,…

More posts from themightymo.com

How to install a Cloudflare SSL on Siteground

How to install a Cloudflare SSL certificate on Siteground

By The Mighty Mo! Design Co. | April 12, 2023

Hey there! In this video, I’ll show you how to install a Cloudflare SSL certificate on your SiteGround website. I’ve noticed that Let’s Encrypt sometimes doesn’t renew properly due to conflicts with Cloudflare, so this is a great solution. We’ll use TCwebsecurity.com as the guinea pig. I’ll walk you through the process step-by-step. Once we…

wayback machine

How to Download a Website from Wayback Machine

By The Mighty Mo! Design Co. | March 27, 2023

Today I ran into an issue where a bunch of website files were deleted off the server, and I was called upon to restore the old files. After first pursuing other options (e.g. backups), I landed on Wayback Machine as the next best choice. Thankfully, there’s a handy command line tool for downloading any site…

wordpress website maintenance

My WordPress Maintenance Process

By The Mighty Mo! Design Co. | March 2, 2023

A few quick things: My WordPress Maintenance Process Demo, Part 1 Transcript: You’ll see immediately after logging in, you see the 11 updates needed as well as some messages. I’m just gonna quickly read. It looks like this. I don’t need to worry about. Are you enjoying Monster Insights? Not really <laugh>. What’s to enjoy…

RSS From Toby’s Blog

  • Fortify Your WordPress Site: Essential Security Steps
    Securing your WordPress site is a critical component of maintaining your online presence and safeguarding your data. Security is no longer a luxury, it has become a necessity in today’s digital world, where threats are lurking at every corner. This piece dives deep into WordPress security basics, giving you a comprehensive understanding of common vulnerabilities…
  • Master Your Site: Customizing WordPress Themes
    Just as a house is more than bricks and mortar, a WordPress site is much more than simple code. It’s a cohesive structure built with various layers such as PHP, HTML, CSS, and other key elements. Customizing WordPress themes involves gaining an in-depth understanding of this structure, learning to inspect and adjust design elements with…
  • Mastering WordPress Basics for Beginners within Hours
    Welcome to the world of WordPress, a widely used Content Management System (CMS) that powers millions of websites worldwide. Being immensely flexible and user-friendly, WordPress offers an endless scope to create, manage, and customize your website according to your needs and preferences. In this segment, we attempt to introduce you to the basics of WordPress,…